Everyone has come to a point where they ask themselves “Can I ping a port? How do I check if this port is open or not?”. Although there’s no way of “pinging” a port, you can still check if a port is active using different methods.
Short answer: You can’t “ping” a port.
Long answer: There are other ways to check if a port on a remote server is active, but using ping is not one of them. If you wish to skip the explanation and go directly to the how-to part go to the How to query a remote host for open ports with telnet or nmap part.
When we use Ping we are actually using the ICMP protocol which operates at Layer 3 of the networking stack and does not have the capability to recognize ports, which are present at the Layer 4 of the networking stack. To understand this first we need to have a little networking knowledge and how the ICMP operates.
There are 7 layers in the networking world, each responsible for handling its own set of data. Understanding networking is a very broad topic for discussion and it is out of the scope of this tutorial. However, for the purposes of understanding the basic concept, in the image below are represented the 7 OSI networking layers and they are counted from the top up.
A brief description of the 7 networking layers is as follows:
Layer 1 – Physical Layer
Provides the means of sending and receiving data through a physical medium. You can think about this level in terms of cables, network cards and other physical aspects of transportation.
Layer 2 – Data-Link Layer
The data packers are encoded and decoded into bits. This layer is divided into two sub-layers, MAC (Media Access Control) sub-layer, and LLC (Logical Link Control) sub-layer. The MAC sub-layer is responsible for caring and managing the physical device addresses (commonly known as Network Interface MAC address). The LLC layer is responsible for error control and flow control.
Layer 3 – Network Layer
Provides logical addresses, which routers and other layer 3 aware networking devices will use to determine the path to the destination. By logical addresses, it is meant on the source and the destination IP addresses. ICMP is a Level 3 protocol. It knows about IP addresses and knows how to reach the given destination. Continue reading about Layer 4 to find out more.
Layer 4 – Transport Layer
Provides flow control of the data, which includes error checking and recovery of the packets. It includes protocols like TCP and UDP. The networking ports are defined in these protocols. Now go back at the Layer 3, and read that again. Now you should understand why you can not “ping a port”. The ICMP protocol is not aware of their existence.
Layer 5 – Session Layer
Establishes and maintains the end to end communication between the devices.
Layer 6 – Presentation Layer
Ensures that the presentation of data is provided at the appropriate form for the recipient. It acts as a translator of the network. For example, when an email is sent the presentation layer will format your data into email format. Or if you want to send photos to your friend, the presentation layer will format your data into GIF, JPG or PNG format.
Layer 7 – Application Layer
The closest layer to the end user. It provides the interface between the applications we use and the other underlying layers. However, the programs that we are using, like a web browser, do not belong to the Application layer. The protocols that those programs use, like Telnet, FTP, SMTP, HTTP and others are examples of the Application layer. Protocols (not applications) are part of this layer.
How to query a remote host for open ports
This brings us to the final answer, how can we check if a remote host has the specified port open?
How can we check if the service is working?
In short, you need to use a few tools that work with one of the higher networking layers.
Telnet
This is the simplest possible way, and very commonly used by the network technicians. Telnet by default works on port 23. When you invoke telnet with its default settings it will check if the remote host has port 23 open, and if a telnet service is present on that port it will initiate the connection. The good thing is that you don’t have to use it like that. You can use this tool to check if any other port is open, and potentially find out the service that runs on the port.
Let’s take a look at a few examples.
## Check if the server (google in our example) has port 785 running (non functional port). The prompt will hang for a while and then will disconnect unsuccessfully. You can try this by providing a hostname or an IP address. # telnet google.com 785 Trying 216.58.192.174... telnet: connect to address 216.58.192.174: Connection timed out telnet: connect to 216.58.192.174: Network is unreachable
Now let’s check the same with something that we will know that it’s working:
# telnet mail.google.com 25 Trying 216.58.192.165... Connected to mail.google.com. Escape character is '^]'.
To exit this prompt use CTRL-]. Don’t get any ideas, though. You can not hack them or anything using this way. This is merely a way to figure out if the specified port is active or not. You can do this with any TCP-based service. A common example of usage is to check if the service is working or to check if a firewall is blocking your service.
NMAP
Nmap is a very useful tool which can be used for many things. Its most simple invocation will scan the target host (by hostname or by IP address) and will display the most commonly used port (1-1024).
# nmap myserver.com Starting Nmap 6.40 ( http://nmap.org ) at 2017-03-02 04:12 CST Nmap scan report for myserver.com (192.168.100.23) Host is up (0.17s latency). Not shown: 993 filtered ports PORT STATE SERVICE 25/tcp open smtp 80/tcp open http 143/tcp open imap 443/tcp open https 465/tcp closed smtps 587/tcp open submission 995/tcp closed pop3s Nmap done: 1 IP address (1 host up) scanned in 12.20 seconds
To check if a specific port is open (i.e. if the service is responding) you can use the following command examples:
## Scan a single port # nmap -p 2080 myserver.com ## Scan multiple ports # nmap -p 25,80,443 myserver.com ## Scan a range of ports # nmap -p 1-10000 myserver.com
Final words
This is was just a brief introduction of how one can perform simple network troubleshooting commands to determine if a specified service is working on a remote server. Besides telnet and nmap, there are other similar commands which operate on a higher networking level and can be used to do the same thing. Ping, however, is just basic level 3 troubleshooting tools, which is most often used by network engineers to troubleshoot network readability.
If you need any help using nmap or telnet, feel free to get a Cloud VPS from us and our expert Linux admins will help you. They are available 24/7 and will take care of your request immediately
PS. If you liked this post please share it with your friends on the social networks using the buttons on the left or simply leave a reply below. Thanks.