November 21, 2024, 04:35:35 PM

News : LinuxSolved.com Linux Help Community Forum..


Author Topic: portforwarding using iptables not working  (Read 6334 times)

Offline ask2me

  • New Member
  • Posts: 1
portforwarding using iptables not working
« on: July 19, 2009, 02:49:23 AM »
Iam a newbie in linux.Recently i tried iptables portforwarding feature in my linux router.I have alreay running a firewall script.
I tested a the portforwarding command


iptables -A FORWARD -i eth1 -j ACCEPT
iptables -A FORWARD -o eth1 -j ACCEPT
iptables -t nat -A PREROUTING -i eth0 -p udp --dport 8081 -j DNAT --to 192.168.10.99:8081
iptables -A FORWARD -i eth0 -p udp --dport 8081 -d 192.168.1.99 -j ACCEPT


But when i tested from outside to connect to the internal machine 192.168.10.99 port 8081, i couldnt.Iam pinned on this problem for the last one month.Kindly give me the reason for not working.
How can i exactly settle the problem.Iam using ubuntu 8.04 with a mailserver installed on it.
Thanks in advance

Offline kaushalpatel1982

  • LST CareTaker
  • Linux Learner
  • *****
  • Posts: 87
Re: portforwarding using iptables not working
« Reply #1 on: September 25, 2009, 02:50:37 PM »
Just use command given below.

#iptables -t nat -A PREROUTING -i eth0 -p udp --dport 8081 -j DNAT --to-destination 192.168.10.99:8081
#iptables -t nat -A POSTROUTING -s 192.168.10.99 -o eth0 -j MASQUERADE

I think there is problem with the return traffic. This might solve your problem. To troubleshoot the exact issue you have to use tcpdump with the port and check what heppen.