Wednesday, April 2, 2014

How to forward ports in linux

If you need to pass over some port numbers from one server to another, you can use port forwarding in linux. It should be very easy as soon as you understand the concept.

Say, you would like to access port 80 on server1. However, server1 is behind firewall (say, a router), and you can login to that router (server2) to ssh port number 2224. Here is how you can do the port forwarding via ssh.


ssh -p 2224 -L 8080:server1:80 youruser@your.router.com

After you login with this command, keep the window open, and you can open your browser pointing to
http://localhost:8080/

Your ssh will forward requests to 8080 to server1:80. That's all!

No comments:

Post a Comment