We’ve all been there. You want to isolate an issue with a server running on a port but want something quick and easy to verify if it is a host firewall problem or something else. Perhaps you are dealing with someone on the other end of the network that says it is a firewall problem. How you prove otherwise?

Luckily, there is socat. While there are other network Swiss army knives out there such as Ncat and Netcat, you might find socat worth a try. Socat is available for most Linux and BSD distributions and there are binaries available for Windows.

Sock It To Me

In this example, we have a service running on a high port (6000) on a machine “tom” and we want to prove that the firewall rule is indeed allowing traffic from the outside world from another machine “jerry”.

In this very simple example, we are logged into tom and start by confirming that socat is installed on tom. Here we simply install the socat package via yum on tom. Next, we’ll make sure that the firewall rules on tom are correct. Finally, we issue the socat one liner to listen on the port we want to test for the firewall allowing incoming traffic on port 6000 and we save our results on tom to /tmp.

Now that we have a service listening on tom it’s time to login to jerry and telnet to the tom on the specified port. We’ll simply type in “Hello world” and then escape from our telnet session.

At this point we can review the file on tom:/tmp to see if our testing was fruitful. Success! Now, time to tell the other end that the problem isn’t with the firewall on your end!

There a huge number of socat one liners out there and the socat documentation is detailed. You can imagine the possibilities if in this example both tom and jerry both have access to socat.

Again, this is a very simple example but the power of socat is how quickly and easily you can verify and solve problems. Of course, socat use cases don’t end there and you can quickly find socat being an indispensable tool for getting things done.

If you already know and love socat, what are some of your favorite one liners?