This is the scenario

I have configured a web-server in MUX. Now I want to access that web-server from Internet. Ubuntu box has two interfaces, One is connected to WAN (Public IP) and another one is connected to MUX (Private IP). MUX has no option to insert default gateway.

iptables -t nat -A PREROUTING -p tcp -i eth0 -d 103.x.x.x --dport 8001 -j DNAT --to-destination
iptables -A FORWARD -p tcp -d --dport 8080 -m state --state NEW,ESTABLISHED,RELATED -j ACCEPT

It does not work.

1 Answer 1


What you want is this:

iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 8081 -m conntrack -ctstate NEW -j DNAT --to
iptables -t nat -A PREROUTING -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT
iptables -A POSTROUTING -t nat -j MASQUERADE

hope this helps.

  • This looks pretty complicated. I want to learn some of it. Do you know some nice documentation I can refer to?
    – SamK
    Oct 18, 2012 at 12:44
  • Use an irc client and connect to irc.freenode.net #iptables Oct 18, 2012 at 14:53
  • 1
    @val0x00ff Is it any problem If I use -m state --state instead of m conntrack --ctstate?
    – user141610
    Oct 20, 2012 at 10:59
  • 1
    @user141610 The difference between the two is explained here: serverfault.com/questions/358996/… Oct 21, 2012 at 18:56

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.