In this paper, we investigate the design of a distributed beamforming technique for two-way relay networks consisting of two transceivers and multiple relay nodes. We consider the problem of the total transmit power minimization subject to two constraints that maintain the transceivers' SNRs above given thresholds γ1 and γ2. For this problem, we obtain a semi-closed-form solution for the beamforming weight vector. Our solution is based on the observation that beamforming weight vector depends on the sum of SNR thresholds γ1 + γ2. As long as this sum does not change, the beamforming weight vector will not change. Hence, a two-way relay vector can be equivalently modeled as a one-way relay network where γ1 and γ2 are replaced with 0 and γ1 + γ2, respectively. Based on this equivalent one-way relaying scheme, the beamforming weight vector is obtained in a closed form if a certain intermediate parameter is given. This parameter is the transmit power of the source in the equivalent one-way relaying scheme and can be obtained efficiently using a simple bisection method. Once this parameter is obtained, the beamforming weight vector can be obtained in a closed form.Index Terms-Distributed beamforming, ad hoc relay networks, two-way relaying, distributed signal processing, SNR balancing, optimal power allocation, bi-directional relaying.