Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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 192.168.1.2:8080
iptables -A FORWARD -p tcp -d 192.168.1.2 --dport 8080 -m state --state NEW,ESTABLISHED,RELATED -j ACCEPT

It does not work.

share|improve this question

1 Answer 1

up vote 1 down vote accepted

What you want is this:

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

hope this helps.

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

Your Answer

 
discard

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.