Checking for an open / listening port….
I’ve had many occasions dealing with network administrators asking them for ports to be open on the firewall so outside users can connect and communicate with various web services. For example, when putting a tomcat site up on port 8080 (this could easily be port 80, 443 or any other port for that matter). I needed the network admin to open port 8080 on the firewall to the outside world…
At that point, if I still could not connect to the website, I needed a way to debug. My first question was always, ‘did he open the port?’, and ‘is the website listening on the correct port 8080?’
How do I really know if the port is open / listening?? How do we know for sure if the firewall rule was done properly and working?
Well here’s a trick I learned using telnet which is readily available on most machines, Windows, Mac, Linux, Red Hat, etc….
At any command prompt type:
# telnet <fill-in-the-ip-address-or-dn-name-here> 8080
<fill-in-the-ip-address-or-dn-name-here> should be the ip address or the domain name of the server that you are testing connectivity to.
You will receive a different response depending on the host’s operating system you’re typing the telnet command on. Also, the response will vary depending on if the port is open or close and there is a service listening on the port.
In Windows, a response like this means the port is open and listening on the targeted server and port:
After the telnet command the screen will go blank if the port is open / listening.
In Unix / Linux the response will look like this if the target port is open and listening:
In both Windows and Unix style operating systems, if the port is not listening the response will look something like this:
In other words, there really won’t be any response. It will just freeze at the ‘Connecting to’ xxx.xxx.xxx.xxx line.