Atlantic.Net Blog

How to Check Open Port on a Remote Linux System

A Port is a logical number assigned to a process running on Linux. Port can be defined as an integer number between 0 to 65535. Ports with numbers 0–1023 are called system or well-known ports, while ports with numbers 49152-65535 are called dynamic, private, or ephemeral ports. If you are a Linux system administrator then you should have the knowledge to find out which ports are open and running on a remote system. There are several ways to find an open port on Linux.

In this post, we will show the most reliable ways to find an open port on a remote Linux system.

Prerequisites

  • A server running Linux on the Atlantic.Net Cloud Platform
  • A root password configured on your server

Create Atlantic.Net Cloud Server

First, log in to your Atlantic.Net Cloud Server. Create a new server, choosing any Linux operating system with at least 1GB RAM. Connect to your Cloud Server via SSH and log in using the credentials highlighted at the top of the page.

Find Open Port Using Netcat Command

Netcat is a Linux command-line utility used to read and write data across network connections using TCP or UDP protocol. It also allows us to find open ports on a remote Linux system.

By default, the Netcat utility is not included in the Linux system. You will need to install it manually using the package manager.

For Ubuntu and Debian-based operating systems, install the Netcat utility using the following command:

apt-get install netcat -y

For RHEL, CentOS, Fedora, and Rocky Linux operating systems, install the Netcat utility using the following command:

dnf install nc -y

The basic syntax to use the Netcat command is shown below:

nc [-options] [host_name or ip] [port_number]

For example, to check if port 80 is open on the remote host 172.20.10.2, run the following command:

nc -zv 172.20.10.2 80

If port 80 is open on a remote host, you will get the following output:

Connection to 172.20.10.2 80 port [tcp/http] succeeded!

Where:

  • -z : Sets nc to simply scan for listening daemons.
  • -v : Show output in verbose mode.

You can also specify a range of ports to be scanned:

nc -zv 172.20.10.2 40-80

The above command will scan for all ports between 40 and 80.

Also Read

Netstat Command Line Tips and Tricks

Find Open Port Using Nmap Command

Nmap is a powerful and very popular command-line utility used to perform network-related tasks. By default, the Nmap utility is not included in the Linux system. You will need to install it manually using the package manager.

For Ubuntu and Debian-based operating systems, install the Nmap utility using the following command:

apt-get install namp -y

For RHEL, CentOS, Fedora, and Rocky Linux operating systems, install the Nmap utility using the following command:

dnf install nmap -y

The basic syntax to use the Nmap command is shown below:

nmap [-options] [HostName or IP] [-p] [PortNumber]

For example, to get a list of all open ports on a remote host 172.20.10.2, run the following command:

nmap 172.20.10.2

You should see all open ports in the following output:

Starting Nmap 7.60 ( https://nmap.org ) at 2022-04-05 14:05 IST
Nmap scan report for vyompc (172.20.10.2)
Host is up (0.000078s latency).
Not shown: 996 closed ports
PORT     STATE SERVICE
22/tcp   open  ssh
23/tcp   open  telnet
80/tcp   open  http
7070/tcp open  realserver

Nmap done: 1 IP address (1 host up) scanned in 0.88 seconds

If you want to check if a particular port is open on the remote host, use the -p option:

nmap -Pn -p 80 172.20.10.2

You will get the following output:

Starting Nmap 7.60 ( https://nmap.org ) at 2022-04-05 14:08 IST
Nmap scan report for vyompc (172.20.10.2)
Host is up (0.00011s latency).

PORT   STATE SERVICE
80/tcp open  http

Nmap done: 1 IP address (1 host up) scanned in 0.04 seconds

Find Open Port Using Telnet Command

Telnet is another network protocol used to virtually access a remote computer. It also allows you to find open ports on remote systems. You can install it manually using the package manager.

For Ubuntu and Debian-based operating systems, install the Telnet utility using the following command:

apt-get install telnet -y

For RHEL, CentOS, Fedora, and Rocky Linux operating systems, install the Telnet utility using the following command:

dnf install telnet -y

The basic syntax to use the Telnet command is shown below:

telnet [HostName or IP] [PortNumber]

For example, to check if port 22 is open on a remote host 172.20.10.2, run the following command:

telnet 172.20.10.2 22

If port 22 is open, you will get the following output:

Trying 172.20.10.2...
Connected to 172.20.10.2.
Escape character is '^]'.
SSH-2.0-OpenSSH_7.6p1 Ubuntu-4ubuntu0.6

If port 22 is not open, you will get the following output:

Trying 172.20.10.2...
telnet: Unable to connect to remote host: Connection refused

Conclusion

In this guide, we have shown how to find an open port on a remote machine using different commands. You can now choose your preferred tool to scan the remote system and find an open port. Try it on VPS hosting from Atlantic.Net!

Get started with 12 months of free cloud VPS hosting

Free Tier includes:
G3.2GB Cloud VPS Server Free to Use for One Year
50 GB of Block Storage Free to Use for One Year
50 GB of Snapshots Free to Use for One Year