Three ways to see if a port is open on a remote Linux system

  • 2021-01-06 00:53:08
  • OfStack

This is an important topic, not only for Linux administrators, but also for all of us. What I mean by that is that it is also useful for users working in the IT infrastructure industry to understand this topic. They need to check that a port is open on the Linux server before performing the next step.

If the port is not open, they will go directly to the Linux administrator to open it. If the port is already open, then we need to discuss with the application team what to do next.

In this article, we'll show you three ways to check if a port is open.

This can be achieved using the following Linux command:

nc nmap telnet

How do I use the nc (netcat) command to check if a port is open on a remote Linux system?

nc netcat namely. netcat is a simple Unix tool that uses the TCP or UDP protocols to read and write data between network connections.

It is designed to be a trusted back-end tool that can be used directly or simply invoked by other programs or scripts.

At the same time, it's a feature-rich tool for debugging and exploring networks, because it can create almost any type of connection you need, and it has several interesting built-in features.

ES34en has three functional modes, which are connection mode, listening mode, and tunnel mode.

nc (netcat) command:


$ nc [-options] [HostName or IP] [PortNumber]

In the following example, we will check to see if port 22 is open on the remote Linux system.

If the port is enabled, you will get output similar to the following.


# nc -zvw3 192.168.1.8 22
Connection to 192.168.1.8 22 port [tcp/ssh] succeeded!

Details of the command:

nc z v w3 192.168.1.8 22

When you detect that the port is not open, you will get the following output:


# nc -zvw3 192.168.1.95 22
nc: connect to 192.168.1.95 port 22 (tcp) failed: Connection refused

How to use the nmap command to check if a port is open on a remote Linux system?

nmap (" Network Mapper ") is an open source tool for network exploration and security auditing that is designed to quickly scan large networks, although it also works well for a single host.

In a novel way, ES68en uses the bare ES69en package to determine whether hosts on the network are reachable, what services they are providing (application name and version number), what operating system they are running (version of the system), what package-filtering software or firewall they are using, and other additional features.

Although nmap is commonly used for security audits, many system and network administrators find it equally useful for routine tasks such as listing network assets, managing plans for service upgrades, and monitoring whether a host or service is up and running.

nmap Common Syntax:


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

If the port is enabled, you will get the following output:


# nmap 192.168.1.8 -p 22

Starting Nmap 7.70 ( https://nmap.org ) at 2019-03-16 03:37 IST Nmap scan report for 192.168.1.8 Host is up (0.00031s latency).

PORT STATE SERVICE

22/tcp open ssh

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

If the port is not open, you will get something like this:


# nmap 192.168.1.8 -p 80
Starting Nmap 7.70 ( https://nmap.org ) at 2019-03-16 04:30 IST
Nmap scan report for 192.168.1.8
Host is up (0.00036s latency).

PORT  STATE SERVICE
80/tcp closed http

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

How to use the telnet command to check if a port is open on a remote Linux system?

The telnet command is used to interactively communicate with another host via the TELNET protocol.

The telnet command has a common syntax:


$ telnet [HostName or IP] [PortNumber]

If the probe is successful, you should see output similar to the following:


$ telnet 192.168.1.9 22
Trying 192.168.1.9...
Connected to 192.168.1.9.
Escape character is '^]'.
SSH-2.0-OpenSSH_5.3
^]
Connection closed by foreign host.

If the probe fails, you will see output similar to the following:


$ telnet 192.168.1.9 80
Trying 192.168.1.9...
telnet: Unable to connect to remote host: Connection refused

Currently, we have only found the above three ways to check if a port is open on a remote Linux system. If you have found other ways to achieve the same purpose, please let us know in the comment box below.

conclusion


Related articles: