This work proposes an in-network distributed algorithm for the energy optimal routing in a wireless sensor network. The routing problem is described as a minimum-cost multi-commodity network flow problem by Linear programming. Based on the convex programming theory we use the dual decomposition theorem to derive the distributed algorithm on a mathematical basic. The algorithm computes the exact energy optimal routing in the network without any central node or the knowledge about the whole network structure, using only peer-to-peer communication between neighboring nodes. In contrast to other works in this area, the presented approach is not limited to strictly convex objective functions and it handles linear objective functions.