Port forwarding using IPTables
I’ve got a UT300R2U ADSL router that has a really bad web based UI that did not let me setup some basic port-forwarding rules.
Thankfully the router was a linux based router with telnet installed on it. I was able to log in using the admin user, and set the following iptable rules:
#iptables -I PREROUTING -t nat -p tcp --dport 8080 -i ppp_0_35_1 -j DNAT --to 192.168.1.11:8080
#iptables -I FORWARD -p tcp -d 192.168.1.11 --dport 8080 -i ppp_0_35_1 -o br0 -j ACCEPT
#iptables -I FORWARD -p tcp -s 192.168.1.11 --sport 8080 -i br0 -o ppp_0_35_1 -j ACCEPT
the IP address 192.168.1.11 is the webserver that’s hosting tomcat on port 8080.
Someone asked how he could forward a range of ports.
To do this, you’d need to specify the port range as ’8000-8080′ instead of just ’8080′ in the example above.
In case you just want to forward UDP instead of TCP, change the ‘-p tcp’ above to ‘-p udp’
Ketan
16 Dec 07 at 8:44 am