How to forward one TCP port to another

Let's pretend you have something running on TCP port 8000, however you want to access it on port 80. You can use socat (ubuntu install link) to forward the connections from port 80 to port 8000. You can do this with any combination of ports. Since port 80 is a retricted port, you need to use sudo. If you are running apache (or others) you will have to stop them to free up port 80

sudo socat TCP-LISTEN:80,fork,reuseaddr TCP:localhost:8000

I use this at work to switch from using the apache server (with WSGI) to using the Django test server

See what gets forwarded

You can add the -v option to socat to make it print out the data that it's transfering. This is helpful for debugging, however it's probably easier to use tcpflow to see this network traffic.

This entry is tagged: