How to ping and test for a specific port from Linux or Unix command line

To ping and test for a specific port on Linux or Unix, you can use the nc (Netcat) command. The nc command is a simple tool for checking if a network port is open and for sending and receiving data over a network.

Here’s how you can use nc to ping a specific port:

  1. Open a terminal and run the following command:
nc -vz <host> <port>

Replace <host> with the hostname or IP address of the target system and <port> with the port number you want to test. The -v option tells nc to run in verbose mode, and the -z option tells nc to only scan for open ports and not send any data.

For example, to ping and test the HTTP port (port 80) on the host www.example.com, you would run the following command:

nc -vz www.example.com 80

If the port is open, nc will print a message indicating that the connection was successful, like this:

Connection to www.example.com 80 port [tcp/http] succeeded!

If the port is closed, nc will print an error message indicating that the connection failed, like this:

nc: connect to www.example.com port 80 (tcp) failed: Connection refused

Leave a Comment