Calamity Lane

Curious Code for Curious Coders

Redir Is Awesome

More than anything, I love tiny tools that do one thing, and do it well. The UNIX philosophy sends me into fits of programmery giggliness for precisely this reason.

Recently I discovered a tiny new tool to add to my toolbox. I had a test server running on port 3014, and needed to briefly expose it on port 80 (I know, I know, I’ve just made myself eligible for a righteous noodle-lashing).

My first instinct was to turn to netcat. I’ve tried netcat many times, and I love the idea of netcat, but I’ve never been able to use it in practice. Due to the various incomprehensibly incompatible versions, simple tasks frequently requires 15+ minutes of Googling, sifting through old man pages, and idle experimentation. The idea is great, the execution is utter failure. Simple things aren’t easy.

Fortunately, I ran across a little program called redir, which does exactly what I need (and, tangentially, is nearly impossible to Google). I installed it on Ubuntu 12.04 using apt-get:

sudo apt-get install redir

This is likely to work on any Debian-based system.

Once I had it installed, running it was straightforward:

sudo redir --lport=80 --cport=3014

Now, any (TCP) traffic coming into my box on port 80 is routed to my server on port 3014.

Like any other UNIX-y tool, redir comes with two boatloads of extra options, flags, and tweaks, but my needs are simple, and handled by the basics of the tool.

Small problem, small tool, simple solution.