Port Forwarding In Linux

For reasons which I will not go into for fear of boring everyone, we were trying to forward local requests on port 80 to port 3000 (running a Rails app), without booting the Rails app on port 80, and without having a web server in the middle to do the redirection.

Enter NetCat.

The default Ubuntu version of NetCat (nc) doesn’t contain the required -c option. In order to do this, you will need to install nmap, which contains a version of NetCat that supports the necessary option:

sudo apt-get install nmap

Then simply run the following command to map the ports:

sudo ncat -l -p 80 -c 'ncat localhost 3000'

That command catches any requests to port 80 on the local machine and forwards them to localhost on port 3000.