Kjetil's Information Center: A Blog About My Projects

TCP proxy with Netcat

Here is an interesting way to setup a generic TCP proxy using the netcat tool. What makes this method interesting is that traffic is not simply forwarded, but also sent back the other way. In order to do this, we require a two Unix pipes. One is created using the shell's own mechanism, and the other one is created manually as a named pipe (also known as a fifo).

Imagine we want to connect with telnet to some remote host, through the proxy like this:
local-host <-> proxy-host <-> remote-host.

On the proxy-host, enter this on the shell:

mkfifo /tmp/backpipe
nc -l -p 31337 < /tmp/backpipe | nc remote-host 23 > /tmp/backpipe
          


On the local-host, you can now enter this...:

telnet proxy-host 31337
          

...to reach port 23 on the remote host, and the traffic will flow in both directions.

Topic: Configuration, by Kjetil @ 18/07-2010, Article Link