I have an ubuntu server (14.04.1) which is asking as a router for my network. It has an internet facing interface, eth0, and a second interface, eth1, for connecting to my network.

I am attempting to forward TCP traffic directed to eth0 (for this example, lets say its IP is to eth1 with an address of for port 27016

I have attempted the following commands in sequence:

sudo echo "1" > /proc/sys/net/ipv4/ip_forward

sudo sysctl net.ipv4.ip_forward=1

sudo iptables -t nat -A PREROUTING -p tcp --dport 27016 -j DNAT --to-destination

sudo iptables -t nat -A POSTROUTING -j MASQUERADE

but this doesnt seem to work at all, i cannot connect to to access the application running on Is it to do with it being across two interfaces or what?


Try adding -i eth0 to your PREROUTING entry and -o eth0 to your POSTROUTING entry and executing sudo iptables -A FORWARD -i eth1 -j ACCEPT

|improve this answer|||||
  • just gave this a shot, postrouting cannot have an interface but other than that both other commands worked, still not able to access via – Trotski94 Dec 24 '14 at 17:47
  • 1
    My mistake. POSTROUTING should have been -o eth0 – Ben Dec 24 '14 at 17:50
  • Given that a shot, still no luck.. odd... EDIT: just noticed the protocol I'm trying to pass is UDP, DUH! ill edit the rules and come back with whether it worked or not. – Trotski94 Dec 24 '14 at 22:14
  • Yep that worked... – Trotski94 Dec 24 '14 at 22:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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