Open a Listening port on Linux

Updated: 3 days ago

How to open a port on Linux is a common question when testing a firewall related problem. Today we will use nc command to open a tcp port manually on Linux and check if this port is working or not.


Use nc or ncat to open a port on Redhat/Centos Linux

Nc or ncat is delivered as part of nmap-ncat rpm in RHEL/CentOS which we can install using yum or dnf. Use --listen with --port to open a port using nc command. In the below example we open port 1234

[root@centos-7 ~]# nc -4 -l 1234

[root@centos-8 ~]# nc --listen --source-port 1234


Open another terminal of this server and check port status

[root@centos-8 ~]# netstat -ntlp | grep 1234

tcp 0 0 0.0.0.0:1234 0.0.0.0:* LISTEN 28983/nc

tcp6 0 0 :::1234 :::* LISTEN 28983/nc


As you see port 1234 is listening for both IPv4 and IPv6. To only use IPv4 use -4 with the above command

[root@centos-8 ~]# nc --listen --source-port 1234 -4

Next on another terminal, you can check the port status for port 1234

Check the port status

[root@centos-8 ~]# netstat -ntlp | grep 1234

tcp 0 0 0.0.0.0:1234 0.0.0.0:* LISTEN 29329/nc


Use nc to open a port on Ubuntu Linux

We can use this command to open the port.

# nc -lk port number


Related Post:

Linux: 5 ways to Check a remote port is open

Thanks a lot for your support.



30 views

Join our newsletter. Get a free Linux account on Cloud.

Get a Free Cloud Server! 

We can use this cloud server to practice Linux commands. Never miss a post!

Thanks for submitting!