5 ways to check if a Port is open on a remote Linux PC

Knowing open ports from a Linux machine allows system administrators to connect to a remote computer, which can fix problems with the system and the cloud server. First, we will show you the TCP and UDP ports and how they are different before we start to find the open ports.

There is an ample number of ways to check for any open ports on a remote Linux PC. Knowing open ports on a Linux machine helps system administrators to connect to the remote PC for troubleshooting system and cloud server issues.

TCP and UDP ports

TCP stands for Transmission Control Protocol. In this method, the computers get connected directly until the data transfer is taking place. Therefore, with this method, the data transfer is guaranteed and is reliable but puts a higher load on the server as it has to monitor the connection and the data transfer too.

UDP stands for User Datagram Protocol. Using this method, the data is sent in the form of little packages into the network with the hope that it reaches the final destination. It means the two computers are not connected directly to each other. This method does not provide any guarantee that the data you send will ever reach its destination. Load on the server is less, and so this method is used commonly by the system administrators first to try something that’s not so important.

Now that you know the types are ports on a Linux system, let’s get started with ways of finding the ones that are open.

Best ways to check if a Port is open on a Linux PC

There are multiple ways you can do it. However, the most reliable way to do this is by using the following commands:

  • nc: netcat command
  • nmap: network mapper tool
  • telnet: telnet command
  • echo > /dev/tcp/..
  • netstat – tuplen

Let’s go through each method one by one.

1. netcat command

netcat is a simple Unix utility that can be used to write and read data using UDP and TCP protocol across network connections.

The primary reason for its design is to provide a back-end tool that works with the scripts and programs. It is also an exploration and network debugging tool that offers tons of features.

To use it, you need to install it in your distro using the respective installation commands.

For Ubuntu/Debian:

sudo apt-get install netcat

For Fedora 22+

dnf install nc


yum install nc

By doing so, you can do the following operations with it.

  • send UDP packets
  • listen to arbitrary UDP and TCP ports
  • Use IPv4 and IPv6 to do port scanning

Moreover, it also has three modes

The syntax of the command is as follows.

nc [-options] host-ip-adress port-number

Let’s try to use it on a remote computer.

$ nc -zvw10 22

Showing nc command succeeding in connecting to an open port

As you can see, the connection succeeded. This means that port 22 is open. If the connection fails, then you will get an error message of “failed: Connection refused”

In the above command, we also used different options. Let’s list them below.

  • z: zero-I/O mode which is used for scanning
  • v: for verbose output
  • w10: timeout wait seconds

2. nmap command

Nmap command is popular network security, auditing, and exploration command. Nmap stands for Network Mapper.

It also has a way to check for open ports. To do so, it utilizes a novel approach to using IP packets. It can also be used to learn about the services the host is providing. Other vital aspects that it can detect include operating system version, packet firewalls/filters, and so on! It is a useful tool.

Let’s see the nmap syntax below.

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

As you can see, its syntax matches that of the nc command. Let’s run it to get a better understanding.

nmap -p 22

Running nmap command to check open port

If the port is closed, then it will show status is closed.

$ nmap -p 103

nmap command shows closed status for 103 port on

3. telnet command

The next command that we will go through is the telnet command. It is an old interactive communication command.

It is specially created for the remote computer interaction, and that’s why we are going to use it to check for open ports on a remote computer. The command is available on both Windows and Linux systems, but on a Windows system, it needs to be enabled before use. It runs over a TCP/IP network. Also, it connects over a remote computer or network equipment over port 23.

One more thing that you need to know is that it is not a secure protocol and must be used with SSH if you want to be encrypted and secure.

To install telnet in RHEL 7 or CentOS 7, you need to use the following command.

# yum install telnet telnet-server -y

For Ubuntu, use the following command

$ sudo apt install telnetd -y

The syntax of the command is as below.

$ telnet [IP or Hostname] [PortNumber]

Shows telnet command in action with a successful connection

If the connection fails, then the port is not open, and you will get the following output.

Shows connection refused using the telnet command

4. echo > /dev/tcp/…

There is another way to check for open ports. In Linux, everything is a file, including the host status and its port availability. This can come handy in cases where no commands are working on the remote host.

The syntax of the command is as below

echo > /dev/tcp/[host]/[port] && echo "Port is open"


echo > /dev/udp/[host]/[port] && echo "Port is open"

Port is “open” output

5. netstat -tuplen

The last command that we are going to discuss is the netstat command. It is a network utility TCP/IP command. It is used to print connections, interface statistics, multicast membership, and other network-related tasks.

The syntax of the command is as below.

netstat -tuplen

It will output the whole list of the IP addresses. The entries that have “Listen” in the “State” column are the open ports.

Shows the output of netstat-tuplen


This leads us to the end of our five ways to check if a Port is open on a remote Linux PC. So, which way are you going to use to connect to your remote Linux PC? Comment below and let us know.

Divya Kiran Kumar
I'm the Editor of FOSS Linux. I worked as a Software Engineer before taking up blogging as my full-time job. I enjoy using Linux, and can't imagine anything else for my PC. Apart from writing for FOSS Linux, I enjoy reading non-fictional books. Sapiens was my favorite last read. I hope you enjoy reading and using this blog to enhance your Linux experience! Have a great day ahead!


Please enter your comment!
Please enter your name here




How to install CMake on Ubuntu

CMake is a cross-platform free and open-source software tool designed to build, test, and package the software. CMake uses a simple platform and compiler-independent configuration files to control the software compilation process.

How to install Lightworks on Ubuntu

Even though Linux may not get a native installer of video editing software like Adobe Premiere or Final Cut Pro, that doesn't mean there are no industry standards tools available. Lightworks is non-linear editing (NLE) video mastering app for Windows, Linux, and macOS. Installing it on Ubuntu is simple due to deb package availability.

How to install DaVinci Resolve on Fedora

Davinci Resolve is a professional application used for color correction, video editing, visual effects, and motion graphics. It is one of the extensively used software by movie industries located in Hollywood.

The 10 Best Programming Languages for Hacking

One of the significant entities we have in Cyber Security is Ethical Hacking (ETH). It is the process of detecting and finding flaws or vulnerabilities in a system that a hacker would exploit.

5 Ways to Open a Terminal in Ubuntu

Even though Ubuntu supports many applications with amazing Graphical User Interfaces (GUI), there are always reasons why users prefer using the Terminal to perform different tasks.

How to install Wine on Fedora Workstation

Linux distributions are becoming more and more popular every day, and Fedora Workstation is not left behind. This popularity brings forth the need to run Windows applications on Linux distros like Fedora. Windows has quite some excellent Software that is not available for Linux.


Linux is growing faster than ever. As per the latest report, there is a drop in the Windows 10 market share for the first time, and Linux's market share has improved to 2.87% this month. Most of the features in the list were rolled out in the Pop OS 20.04. Let's a detailed look into the new features, how to upgrade, and a ride through video.
Elementary OS 5.1 Hera has received a point release with a handful of new features and bug fixes, and we will be reviewing the significant changes in this article. For those new to elementary OS, this Ubuntu-based Linux distribution uses their inhouse built Pantheon desktop environment and AppCenter.

CopyQ – Advanced clipboard manager for Linux

We have all had that moment when we copied a text, but we first needed another one, and in the process, lost the first one. If you're lucky, you can get it back quickly with a bit of work.

What is FOSS, and how does it differ from Freeware

The rise of the Linux operating system, in all its various distributions, over the past few decades has catapulted the popularity of Free or Open Source Software (FOSS). Let's guide you in understanding what is FOSS, how it differs from freeware and is Linux a FOSS.

VIDEO: MX Linux 19 Features and Desktop Tour

MX Linux is a Linux distribution based on Debian stable and using core antiX components. The distributions MX Tools is very popular among users and combined with other several ready-to-use tools, it is great for users who prefer to tweak their distro to their liking. In this video, we will take you through the features tour showing casing MX Linux 19.

All about Ubuntu editions and which version should you use?

Ubuntu is one of the most popular Linux distributions developed and released by Canonical, and not without reason. It has very enriched repositories, with support for all the programs you could ever need.