Home Linux System Administration How To Ping Specific Port Number

How To Ping Specific Port Number

by schkn

Pinging ports is one of the most effective troubleshooting technique in order to see if a service is alive or not.

Used by system administrators on a daily basis, the ping command, relying on the ICMP protocol, retrieves operational information about remote hosts.

However, pinging hosts is not always sufficient : you may need to ping a specific port on your server.

This specific port might be related to a database, or to an Apache web server or even to a proxy server on your network.

In this tutorial, we are going to see how you can ping a specific port using a variety of different commands.

Ping Specific Port using telnet

The easiest way to ping a specific port is to use the telnet command followed by the IP address and the port that you want to ping.

You can also specify a domain name instead of an IP address followed by the specific port to be pinged.

$ telnet <ip_address> <port_number>

$ telnet <domain_name> <port_number>

The “telnet” command is valid for Windows and Unix operating systems.

If you are facing the “telnet : command not found” error on your system, you will have to install telnet on your system by running the following commands.

$ sudo apt-get install telnet

As an example, let’s say that we have a website running on an Apache Web Server on the 192.168.178.2 IP address on our local network.

By default, websites are running on port 80 : this is the specific port that we are going to ping to see if our website is active.

$ telnet 192.168.178.2 80

Trying 192.168.178.2...
Connected to 192.168.178.2.
Escape character is '^]'.

$ telnet 192.168.178.2 389
Connected to 192.168.178.2.
Escape character is '^]'.

Being able to connect to your remote host simply means that your service is up and running.

In order to quit the Telnet utility, you can use the “Ctrl” + “]” keystrokes to escape and execute the “q” command to quit.

ping specific port using telnet

Ping Specific Port using nc

In order to ping a specific port number, execute the “nc” command with the “v” option for “verbose”, “z” for “scanning” and specify the host as well as the port to be pinged.

You can also specify a domain name instead of an IP address followed by the port that you want to ping.

$ nc -vz <host> <port_number>

$ nc -vz <domain> <port_number>

This command works for Unix systems but you can find netcat alternatives online for Windows.

If the “nc” command is not found on your system, you will need to install by running the “apt-get install” command as a sudo user.

$ sudo apt-get install netcat

As an example, let’s say that you want to ping a remote HTTP website on its port 80, you would run the following command.

$ nc -vz amazon.com 80

amazon.com [<ip_address>] 80 (http) open
ping port using netcat command

As you can see, the connection was successfully opened on port 80.

On the other hand, if you try to ping a specific port that is not open, you will get the following error message.

$ nc -vz amazon.com 389

amazon.com [<ip_address>] 389 (ldap) : Connection refused

Ping Ports using nmap

A very easy way to ping a specific port is to use the nmap command with the “-p” option for port and specify the port number as well as the hostname to be scanned.

$ nmap -p <port_number> <ip_address>

$ nmap -p <port_number> <domain_name>

Note : if you are using nmap, please note that you should be aware of legal issues that may come along with it. For this tutorial, we are assuming that you are scanning local ports for monitoring purposes only.

If the “nmap” command is not available on your host, you will have to install it.

$ sudo apt-get install nmap

As an example, let’s say that you want to ping the “192.168.178.35/24” on your local network on the default LDAP port : 389.

$ nmap -p 389 192.168.178.35/24
ping specific port using nmap command

As you can see, the port 389 is said to be open on this virtual machine stating that an OpenLDAP server is running there.

Scanning port range using nmap

In order to scan a range of ports using nmap, you can execute “nmap” with the “p” option for “ports” and specify the range to be pinged.

$ nmap -p 1-100 <ip_address>

$ nmap -p 1-100 <hostname>

Again, if we try to scan a port range on the “192.168.178.35/24”, we would run the following command

$ nmap -p 1-100 192.168.178.35/24
scanning range of ports using nmap

Ping Specific Port using Powershell

If you are running a computer in a Windows environment, you can ping specific port numbers using Powershell.

This option can be very useful if you plan on including this functionality in automated scripts.

In order to ping a specific port using Powershell, you have to use the “Test-NetConnection” command followed by the IP address and the port number to be pinged.

$ Test-NetConnection <ip_address> -p <port_number>

As an example, let’s say that we want to ping the “192.168.178.35/24” host on the port 389.

To achieve that, we would run the following command

$ Test-NetConnection 192.168.178.35 -p 389
ping port on windows using powershell

On the last line, you are able to see if the TCP call succeeded or not : in our case, it did reach the port on the 389 port.

Word on Ping Terminology

Technically, there is no such thing as “pinging” a specific port on a host.

Sending a “ping” request to a remote host means that you are using the ICMP protocol in order to check network connectivity.

ICMP is mainly used in order to diagnose network problems that would prevent you from reaching hosts.

When you are “pinging a port“, you are in reality establishing a TCP connection between your computer and a remote host on a specific port.

However, it is extremely common for engineers to state that they are “pinging a port” but in reality they are either scanning or opening TCP connections.

Conclusion

In this tutorial, you learnt all the ways that can be used in order to ping a specific port.

Most of the commands used in this tutorial can be used on Windows, Unix or MacOS operating systems.

They might not be directly available to you, but you will be able to find free and open source alternatives for your operating system.

If you are interested in Linux System Administration, we have a complete section dedicated to it on the website, so make sure to check it out!

You may also like

10 comments

No one February 9, 2020 - 3:08 pm

No no no no no no no no no no no no no no no no no no.
Ping is this [1].
Read this up, please [2].
“You can’t ping ports, as Ping is using ICMP which doesn’t have the concept of ports. Ports belong to the transport layer protocols like TCP and UDP. However, you could use nmap to see whether ports are open or not”

[1]: https://tools.ietf.org/html/rfc792
[2]: https://serverfault.com/questions/309357/ping-a-specific-port

Reply
Someone February 9, 2020 - 3:11 pm

The post is actually useful and well documented, but the title and the name of the paragraphs…
Don’t fall in the hole of spreading ignorance because you want more followers..
Stick to science.
Spread the knowledge as always but do it in a correct way 🙂

Reply
schkn February 9, 2020 - 3:34 pm

Hello and thank you for your comment.

However, have you read the last paragraph?

I have actually made it very clear that there is no such thing as “pinging a port”.
On the other hand, I had to reconcile engineers’ search intent (“pinging a port”) to the actual networking science behind it : using “ping” to describe testing application availability.

Thank you for the links.

Reply
M June 2, 2020 - 4:35 pm

First, you have good information on how to test tcp connectivity to specific port.

However, to the point of the other commentor’s, it is misleading to have the majority of article reinforce the idea that you can “ping a port” and then end with it isn’t technical possible. 🙂

I think a quick restructure of the article would clear this up and help promote people using the correct terminology. For example, inform the reader in the first paragraph that “Pinging a Port” is a misnomer and this is why and what people are trying to say is test tcp connectivity to a port.

Also, pointing out that people should understand the difference between UDP, TCP, and Ping with a quick example. Primarily the difference between UDP and TCP. Can’t tell you how many times I have had to explain a TCP port being open does not equal UDP, and vice versa.

Anyways, thanks for including the powershell info that is what brought me here.

Reply
Sam March 1, 2021 - 10:16 pm

I really learned something from reading this article thank you 👍🏻

Reply
Conrad February 8, 2022 - 8:20 am

The title matched my google search and lead me here.
The article is well written, gives a variety of options to solve my problem and explains why my initial search of “pinging a port” is not possible.
I learned a lot, thank you

Reply
Foo March 7, 2022 - 5:47 pm

People trying to flex on you have no imagination and/or didn’t read the article. I only have 30 years experience in the field and found nothing wrong with this at all. We all talk about “pinging” a web server (port) and “pinging” a host (icmp), though they are two different things. Heck, we talk about “pinging” people, and I don’t know anyone that supports icmp!

Reply
Chris October 16, 2022 - 5:07 pm

great info! thanks!
I’ve been a computer technician for over 30 yrs. I didn’t deal with the same stuff all of the time so coming back to ‘ping’ (“ping /?”) wasn’t enough to refresh my memory.
searching ‘ping syntax include port’ was what brought me here. Now i can be productive again. thanks!

Reply
Ib March 14, 2023 - 12:31 pm

Just a heads up, if using an older version of Powershell, or Powershell ISE, you might need to write -port instead, of -p

Reply
jared March 16, 2023 - 6:48 am

Thanks very much for this information. Useful to know for Windows and Linux.
Searching Google for ‘ping on a specific port’ is what many people want todo, but as your article explains, you cannot ping a port.
So well-done on clearing that up and of course giving the methods to test connectivity on ports.

Reply

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.