“Ping” a specific port on a remote host

“Ping” a specific port on a remote host

One of the things you’ll find yourself needing to do is check if a port on a remote host is open or closed. This is usually helpful when troubleshooting an issue such as if when a service is gone offline and you want to rule out firewall issues. The “ping” command itself isn’t used for this purpose as it checks if a remote host is reachable or not.

Instead you’ll have to use nmap. It’s a “ping for ports” tool available on Linux/Unix systems. To check it port is open, type;

nmap -p 80 example.com

nmap will return the state of the service; open, closed or filtered.  

open means the port is opened via the firewall and there’s a listening application on it.
closed means the port is accessible but there’s no application listening on it.
filtered means nmap  cannot determine whether the port is open because packet filtering prevents its probes from reaching the port.

If you running Mac, then you can install nmap via homebrew brew install nmap . And if you’re on Windows, download from nmap.org.

Another great way to test a remote port is to use telnet. The utility is available on Windows, Mac and Linux. On Windows you’ll have to enable it from optional windows features first.

# telnet davidokwii.com 80
Connected to davidokwii.com.
Escape character is ‘^]’.“`

If you see output similar to the one above, it means the port is accessible. To return control to console, hit Ctrl+]. Otherwise if the output is just “trying…”, then the port is most likely inaccessible. Either service is down or port is blocked at firewall level.

Finally, you can use netcat. Although it very old utility, it’s still very robust.

nc -vz davidokwii.com 80
Connection to davidokwii.com 80 port [tcp/http] succeeded!

nmap, netcat and telnet are your best arsenal for doing basic network troubleshooting for services running on your environment.

Leave a comment

Your email address will not be published. Required fields are marked *