Sign up ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I have the following setup:

Box1 [server]:
eth0 with ip is in the internal network with webserver running on port 80.

Box2 [gateway]:
eth0 with ip with some port exposed to internet e.g. port number 3000.
eth1 with ip is for the internal network

Box3 [client]:
eth0 with ip

Goal is to redirect the traffic from to It looks like simple DNAT rule would work but the problem is that gateway is filtered by some other firewall(black-box) so that only established sessions are accepted in the output chain of the black-box. In other words, if I am listening to port 4000 at, I won't be able to connect to from but the other way is possible i.e. I can connect from to Currently, I have following rules in the gateway:

iptables -A PREROUTING -t nat -i eth0 -p tcp --dport 3000 -j DNAT --to
iptables -A POSTROUTING -t nat -j MASQUERADE -o eth0
iptables -A FORWARD -p tcp -i eth0 -o eth1 -d --dport 3000 -j ACCEPT

sysctl -w net.ipv4.conf.eth0.forwarding=1    #to enable forwarding by kernel.

tcpdump show that gateway is sending response packets to the client but the client is not able to receive any. My best guess is that this is somehow related to session being lost at the iptables but I not a pro in iptables rules. Any clue as to what I could be missing here?

share|improve this question

1 Answer 1

I think that the following lines should do the trick:

sysctl -w net.ipv4.ip_forward=1

iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 80 -j DNAT --to-destination
iptables -A FORWARD -p tcp -i eth0 -o eth1 -d --dport 80 -j ACCEPT
share|improve this answer

Your Answer


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.