Pages

Friday, July 17, 2015

Port forwarding in Linux

To access a machine not directly accessible on network, port forwarding can be used from an accessible machine to the destination machine. 

One common scenario where port forwarding is useful is where a process, like web server, is on a machine with no x-window/browser and it is not directly accessible from the machine running the browser, but an accessible "gateway" machine is available in between.

The following can be run on the "gateway" machine:
ssh <user>@<gateway-host> -L <port>:<destination-host>:<destination-port> -g -N

As long as this process is running, gateway-host:port will show the content from <destination-host>:<destination-port>.