Sunday 11 December 2011

Problem with Port forwarding (IPTables)

Problem with Port forwarding (IPTables)

Hi all,

I have a machine which I am using as a internet (via ppp0) and dhcp server (via eth0) (Debian 6.0.3). -IP: 192.168.2.1


I have another machine connected to the server with IP: 192.168.2.167

I want to forward the internal port 16000 of the 192.168.2.167 to the external port 13201 of the ppp0 (external and dynamic ip).

I tried the following command:
#iptables -A PREROUTING -t nat -i ppp0 -p tcp --dport 13201 -j DNAT --to 192.168.2.107:16000

and

iptables -A FORWARD -p tcp -d 192.168.2.107 --dport 16000 -m state --state NEW,ESTABLISHED,RELATED -j ACCEPT


In the Nat table, I have:
Chain PREROUTING (policy ACCEPT)
target prot opt source destination
DNAT tcp -- anywhere anywhere tcp dpt:13201 to:192.168.2.107:16000

Chain POSTROUTING (policy ACCEPT)
target prot opt source destination
MASQUERADE all -- anywhere anywhere

Chain OUTPUT (policy ACCEPT)
target prot opt source destination


IPTABLES:

Chain FORWARD (policy ACCEPT)
target prot opt source destination
ACCEPT tcp -- anywhere moon.local tcp dpt:16000 state NEW,RELATED,ESTABLISHED

However when I try on the external ip with port 13201 or I use nmap to lookup the external ip I can't see port 13201 opened or use it. Also have dnsmasq I think that's why iptable puts the domain as moon.local (192.168.2.107).

Someone can help me understand why is the port not forwarding??

Thanks for your help!

:)

No comments:

Post a Comment