Port forwarding (sometimes referred to as tunneling) is the act of forwarding a network port from one network node to another. This technique can allow an external user to reach a port on a private IP address (inside a LAN) from the outside via a NAT-enabled router.
Port forwarding allows remote computers (e.g. public machines on the Internet) to connect to a specific computer within a private LAN.
For example:
* forwarding ports 80 or 443 to run an HTTP webserver
* forwarding port 22 to allow Secure Shell access
* forwarding port 21 to allow FTP access
example:
Take vi editor copy and paste the script below. Replace “211.111.111.111″ ip with your Static ip and “192.168.0.22″ with your local ip. Portforwarding of http and ssh port is done here in the example.
save the script with a file name and give executing permission ie
chmod 777 <”filename”>
and execute it….
#!/bin/sh
iptables -t nat -A POSTROUTING -o eth1 -j MASQUERADE
/sbin/iptables -t nat -A PREROUTING -p tcp -i eth0 -d 211.111.111.111 –dport 8181 -j DNAT –to 192.168.0.22:80
/sbin/iptables -A FORWARD -p tcp -i eth1 -d 192.168.0.22 –dport 80 -j ACCEPT
/sbin/iptables -t nat -A PREROUTING -p tcp -i eth0 -d 211.111.111.111 –dport 2222 -j DNAT –to 192.168.0.22:22
/sbin/iptables -A FORWARD -p tcp -i eth1 -d 192.168.0.22 –dport 22 -j ACCEPT
