Skip to content

How to use echo or cat when nc, ss, netstat, curl, etc not available on the host to check if the port is listening

I came across this amazing way of testing if I could reach a port on the host, when literally nothing I tried was available:

vagrant@ ~ () $ echo hi |  nc -l -p  8089 &
[1] 13651
vagrant@ ~ () $ cat < /dev/tcp/127.0.0.1/8089
hi
[1]+  Done                    echo hi | nc -l -p 8089
vagrant@ ~ () $
vagrant@ ~ () $ cat < /dev/tcp/127.0.0.1/8089
-bash: connect: Connection refused
-bash: /dev/tcp/127.0.0.1/8089: Connection refused

Yes, it is just cat, you can also use echo etc, basically reading directly from opened TCP socket.
So above, we run nc to listen on port 8089 and send hi when something connected to it.
Then we open socket with cat we simply get the response!