Open a Listening port on Linux

Updated: Feb 2

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-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 get port open.

# nc -lk port number


Related Post:

Linux: 5 ways to Check a remote port is open

Thanks a lot for your support.



24 views

Join our mail group. Get a free Linux account on Cloud.

Never miss a post!

Want a free Linux account?  This account can be used to login to our cloud server and practice Linux commands.

 
kamateravps.gif
topbackgroud.png

✔ Linux Commands   ✔ Linux Skills    ✔ LinuxPerformance   ✔ Linux Interview

Some articles are from the public internet. If you find your article misused or undesired here and you don't want us to display it, please let us know and we'll remove it immediately.