Port forwarding with SSH

[problem]

You want to forward all traffic from a port on your box, to another host/port combination.

[/problem]

[solution]

The command in the example will port forward, from the local box – any traffic sent to port 8081, will be sent to port 8080 on www.example.com:

[/solution]

[example]

ssh -x -g -L 8081:www.example.com:8080 localhost

Don’t forget, if you need to open LINUX (FC4) firewall, do this (as root):

vi /etc/sysconfig/iptables # add following line then save, exit
-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 8081 -j ACCEPT
/etc/init.d/iptables restart

[/example]

[reference]

[tags]Port forwarding, SSH, Unix Coding School[/tags]

[/reference]

If you have found my website useful, please consider buying me a coffee below 😉

Leave a Reply

Your email address will not be published. Required fields are marked *