Netcat: Check if Remote TCP/UDP Ports are Open / Linux / CentOS / Netcat: Check if Remote TCP/UDP Ports are Open

Netcat is a classic Unix tool that allows you to check open TCP and UDP ports on a remote computer. The netcat tool can be used on both Linux and Windows.

Installing netcat:

  • On CentOS/RHEL:
     sudo yum install nc
  • On Debian/Ubuntu:
     sudo apt update
    sudo apt install netcat
  • On Windows: a ported version of netcat for Windows can be downloaded here (

Below are some examples of using netcat to test network connectivity and open ports.

Checking TCP port 53 on a remote computer:

nc -zv 53

[] 53 (domain) open
In this example, TCP port 53 (DNS) is open.

Options used :

–z – to scan the remote service port without actually sending data;
-v – enables verbose mode;
-n – allows you to skip DNS lookups (port scanning will be faster).

You can scan multiple ports using a single command:

nc -nzv 445 3389 25

Or run a port range scan:

nc -nzv 20-30

The command will return a list of open ports in the specified range.

You can also check UDP ports. For example, let’s check if UDP port 139 (NETBIOS Session Service) is open:

nc -uv 139

In both cases, the command returned that the specified port is open.

If the port is closed, netcat will return:
[] 25 (smtp) : Connection refused.
Note that netcat returns the name of the remote service if one of the standard TCP/UDP port numbers is used.

The netcat tool also allows you to start listening on a specific port on your computer. The command used is:

nc -l 5000

In this mode, everything that comes to this port is output to the console.

Leave a Reply

Your email address will not be published. Required fields are marked *