On my Ubuntu 14.04 I have a service running on a local IP ( and port 80. In my network, my Ubuntu computer has IP Now I want to redirect all traffic on to (note that this is a local IP on the Ubuntu machine). How can I do that?


What you're looking for is called NAT.

First we want to enable portforwarding:

sysctl net.ipv4.ip_forward=1

Now we should add a rule that forwards all incoming traffic on 8080:

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

Then all that is left, is iptables to masquerade

iptables -t nat -A POSTROUTING -j MASQUERADE

What is masquerade?

  • Thank you! I now get the following message after trying to reach -> ERR_CONNECTION_REFUSED. How can I resolve this? – www.data-blogger.com Mar 29 '16 at 15:24
  • @Kevin - are you able to reach Also please post output of iptables -nvL – rowan Mar 29 '16 at 15:29
  • Yes @FAT32, but I am not able to reach the – www.data-blogger.com Mar 29 '16 at 15:31
  • @Kevin - Please post output of iptables -nvL – rowan Mar 29 '16 at 15:32
  • Ah, it is working (I can reach it through the network) @FAT32, but not on my local machine, thank you! – www.data-blogger.com Mar 29 '16 at 15:33

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.