Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

This is our situation, we want traffic that comes in to our server A ip to be sent(tunneled) to a specific ip on server B, and accept replies coming back from server B to server A. How can this be done with iptables?

share|improve this question
1  
Why are you doing this? –  Jeff Ferland Apr 9 '12 at 19:15
add comment

2 Answers

to ensure that traffic both ways passes the server A run apply on it following iptables rules:

# this will forward all the relevant traffic to the server b
iptables -t nat -A PREROUTING -p tcp --dport 1234 -d ip.address.of.a -j DNAT --to ip.address.of.b:1234
# and this will make sure there's no triangular routing - all packets forwarded to b 
# will have source  ip address of a, return communication will always go via a
iptables -t nat -A POSTROUTING -p tcp --dport 1234 -d ip.address.of.b -j MASQUERADE 

if just forwarding is not enough - i suggest you establish a vpn between a and b [using openvp, ipsec or just ssh port forwarding with a watchdog] and apply similar firewall rules.

share|improve this answer
    
+1 -- I forgot to SNAT / masquerade in my answer. –  Jeff Ferland Apr 9 '12 at 20:40
    
@JeffFerland - just DNAT can work - it all depends on other statefull devices between the initiator of the connection and server b. –  pQd Apr 9 '12 at 21:58
add comment

In linux you just install rinetd for your distro and configure the parameters, and you are done.

Windows has a port as well: http://www.ehowstuff.com/how-to-install-and-configure-port-forwarding-using-rinetd-in-windows/

Yes, iptables can do that as well but I have always used rinetd as it is more straightforward.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.