How to Ping Specific Port Number in Linux

Ping specific port in linux

The ping command in Linux checks if a host or IP address is reachable by sending ICMP packets. While it’s useful for testing basic connectivity, it cannot check whether a specific port is open. This is because the ping command doesn’t interact with transport layer protocols like TCP or UDP. To check the status of a specific port, we need tools designed to probe ports directly. 

In this guide, we’ll show how to use Linux tools like telnet, nc (netcat), and nmap to test if a port is open, closed, or filtered. These tools help troubleshoot network issues and verify that services, such as SSH or web servers, are running properly.

Ping a Specific Port Using Telnet

Telnet in Linux is a command-line tool that lets you connect to a remote system and interact with it over the network. You can use it to check if a specific port is open on a server. To do this, run the following command:

telnet [address] [port-number]

Here, replace [address] with the domain name or IP of the server, and [port-number] with the port you want to test. For example, the command below tests if HTTPS (port 443) is open on ultahost.com:

telnet ultahost.com 443

If the port is open, Telnet will connect successfully:

ping port number with telnet

However, if the specified port is closed or blocked, you’ll see a connection error message.

Check a Port Using Netcat (nc)

Netcat, or nc, is a powerful command-line tool used for reading and writing data across network connections using TCP or UDP. It’s often used to check if a specific port on a server is open. To test a port with Netcat, use the following command:

nc -vz [address] [port-number]

Here, the -v option enables detailed output so you can see what’s happening, and the -z option tells Netcat to scan the port without sending any actual data.

For example, to test port 443 on ultahost.com, run the command below:

nc -vz google.com 443

The output below demonstrates that Netcat successfully connected to port 443 on google.com. The message confirms that the port is open and reachable. Here, the DNS mismatch warning simply indicates that the IP address’s reverse DNS entry does not exactly match the domain name. This is common and not an error in most cases:

ping port netstat

If the port is closed, you see a “connection refused” or “timed out” message.

Ping Port Number Using Nmap

Nmap is a powerful network scanning tool commonly used for finding open ports and identifying potential security issues. It’s also helpful for checking the status of specific ports on a server. Before proceeding with the command usage, make sure Nmap is installed on your system. 

You can use the following syntax to check a single port using Nmap:

nmap -p [port-number] [address]

Replace [port-number] with the port you want to test and [address] with the domain or IP, as shown below:

nmap -p 443 google.com

This command scans port 443 on google.com and shows whether it is open or closed. The output also includes information about the service running on that port and how long the scan took:

ping specific port with nmap

To scan multiple ports at once, you can enter a range like this:

nmap -p 20-25 ultahost.com

This command checks ports from 20 to 25, which includes commonly used services like FTP (20, 21), SSH (22), and SMTP (25), and then reports their status:

ping multiple ports nmap

Check a Port Using curl

The curl command primarily sends HTTP or HTTPS requests, but you can also use it to check if a specific port is open by connecting to a web service on that port. The following snippet shows the basic syntax for using the curl command:

curl [protocol]://[address]:[port-number]

For example, you can run the following command to test if port 80 is open on example.com:

curl -I http://example.com:80

The output confirms that port 80 on example.com is open and responding with valid HTTP headers, indicating the web server is active and reachable:

ping port with curl

Conclusion

The ping command in Linux helps us verify if a host is reachable; however, it doesn’t check the status of specific ports. For that, Linux offers several practical tools, such as Telnet, Netcat (nc), Nmap, and curl, each serving a unique purpose. Telnet is great for quick connection checks, Netcat offers flexible TCP or UDP probing, Nmap provides detailed port scanning and service detection, and curl works well for testing HTTP or HTTPS ports. In this article, we explained how to ping a port using these methods to effectively diagnose port-related issues and ensure your services are accessible over the network.

Deploy your virtual server with advanced DDoS Protected VPS Hosting and keep your business or online service secure from cyber threats. With UltaHost’s robust firewalls, you can stay online with peace of mind. Enjoy easy management, 24/7 support, and reliable performance perfect for hosting critical applications, websites, or game servers without interruptions.

FAQ

Can I use the ping command to check if a port is open on a server?
What is the best tool to check if a specific port is open in Linux?
How do I check if port 22 (SSH) is open using Netcat?
What does a “connection refused” message mean when using Telnet or Netcat?
Is it normal to see DNS mismatch warning when checking ports?
What does the “-I” option do in the curl command?
Which ports should I test to check common services?

Related Post

What Is the .bashrc File in Linux?

The .bashrc file is a shell script that runs every time...

How to Install Nmap on Windows?

Nmap, or Network Mapper, is a free and open-source secu...

How to Delete Lines in Vim and Vi

Vim and Vi are popular text editors often used in Unix-...

lsof Command in Linux with Examples

lsof command stands for "list open files" and it is inc...

How to Fix “ifconfig: Command not Found...

Displaying the error "ifconfig: command not found" on a...

How to Install Graphical Uncomplicated Firewa...

Ubuntu provides a pre-installed firewall configuration ...

Leave a Comment