I have a STUN service running on the same machine that is the gateway for the LAN, I would like the results from the STUN service be the same for both internal and external machines. Currently since the masquerading is done in the postrouting rule when the packets leave the gateway the STUN server will just see the LAN IP/port instead of the natted ip/port.

eth1 (lan):
eth0 (wan):
iptables -A POSTROUTING -t nat -o eth0 -j MASQUERADE 
iptables -A INPUT -p udp -d --dport 3701 -j ACCEPT

When a LAN machine with IP contacts the STUN service at the packets get through but the STUN service see that the packet gets sent from

How can I get the NAT translation to occur before the packet arrive to the STUN service and that the response back from the STUN service won't be from but rather the used when contacting the service?

1 Answer 1


Look at the image. Packets gets translated by MASQUERADE when they are to be routed. But your destionation host it the same host as router. So packet won't go through nat-POSTROUTING chain and won't be translated. They will go through filter table instead

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .