How to ping port in Linux

It is possible to determine whether or not a specific port is open on a remote system by using tools such as nmap or telnet on a Linux system.

New users may be surprised that a command like ping is rather useless in this context, as the tool cannot tell us whether a specific port is open or not. Instead, it just tests connectivity to another system by sending ICMP packets.

In this tutorial, we will show you how to install the nmap and/or telnet utility on major Linux distros, and then go over example commands that can be used to check whether or not a specific port on a remote system is open and listening.

In this tutorial you will learn:

  • How to install nmap and telnet on major Linux distros
  • How to perform a broad or specific port scan with nmap
  • How to test a specific port with telnet command
How to ping port in Linux
How to ping port in Linux
Software Requirements and Linux Command Line Conventions
Category Requirements, Conventions or Software Version Used
System Any Linux system
Software nmap, telnet
Other Privileged access to your Linux system as root or via the sudo command.
Conventions # – requires given linux commands to be executed with root privileges either directly as a root user or by use of sudo command
$ – requires given linux commands to be executed as a regular non-privileged user

How to install nmap and telnet on major Linux distros




The two tools we will be covering in this tutorial are nmap and telnet. By default, one or both tools may not be already installed on your Linux disto.

You can use the appropriate command below to install nmap and/or telnet with your system’s package manager.

To install nmap and/or telnet on Ubuntu, Debian, and Linux Mint:

$ sudo apt install nmap telnet

To install nmap and/or telnet on Fedora, CentOS, AlmaLinux, and Red Hat:

$ sudo dnf install nmap telnet

To install nmap and/or telnet on Arch Linux and Manjaro:

$ sudo pacman -S nmap inetutils

How to ping a specific port with nmap

  1. In the example below we test whether a port number of TCP port 80 is open on host google.com:
    $ nmap -p 80 -sT google.com
    

    or

    $ nmap -p 80 google.com
    
  2. To test a UDP port 80, use:
    $ nmap -p 80 -sU google.com
    
  3. Scan remote host 8.8.8.8 for all open port TCP ports:
    $ nmap 8.8.8.8
    
  4. Scan remote host 8.8.8.8 for all TCP and UDP ports:
    $ nmap -sUT 8.8.8.8
    
  5. Scan remote host 8.8.8.8 TCP port 53:


    $ sudo nmap -p 53 8.8.8.8
    
  6. Scan remote host 8.8.8.8 UDP port 53:
    $ nmap -sU -p 53 8.8.8.8
    
  7. Scan remote host 8.8.8.8 for open TCP and UDP ports:
    $ nmap -sUT --open 8.8.8.8
    
  8. Scan you local Ubuntu system TCP ports:
    $ nmap localhost
    

How to ping a specific port with telnet

  1. The other way to test whether a specific port is open on a remote server is to use telnet command. You can specify a target device via hostname, domain name, or IP address. Try connecting to a specific port by specifying the number after the host. Below we test whether a port 443 on host google.com is open:
    $ telnet google.com 443
    Trying 74.125.237.19...
    Connected to google.com.
    Escape character is '^]'.
    

    The third line confirms that we’ve established a successful connection, meaning the port is open and listening.

  2. The following example checks to see if example.com is open on port 80.
    $ telnet example.com 80
    
  3. You can also interact with the connection. For example, to retrieve html from the site, we can paste the following snippet after a connection is established.
    GET /index.html HTTP/1.0
    Host: example.com
    
    
    

    Take note of the two extra line breaks, as these are also necessary.

Closing Thoughts




In this tutorial, we saw how to install and use nmap and telnet on a Linux system in order to ping specific ports on a remote server. Either tool works very well to quickly determine whether or not a port is open and listening.



Comments and Discussions
Linux Forum