In this guide, we will show you how to use the simple Netcat (NC) command to determine if the port on the remote host is accessible/open.
Netcat (or NC) is a powerful and Easy-to-use program that can be used in Linux for anything related to TCP, UDP, or UNIX domain sockets.
# yum Install NC [in Centos/rhel]
# DNF Install NC [in Fedora 22+]
$ sudo apt-get install [in In Debian/ubuntu]
We can use it to open a TCP connection, listen on arbitrary TCP and UDP ports, send UDP packets, and port scans in IPV4 and IPV6.
With Netcat, you can check for a single or multiple open port range, as shown below. The following command will help us see if Port 22 is open on the host 192.168.22.43:
Nc-zv 192.168.22.43
Connection to 192.168.22.43 Port [Tcp/ssh] succeeded!
The results that are not open are:
Nc-zv 192.168.22.43 6380
nc:connect to 192.168.22.43 Port 6380 (TCP) Failed:connection refused
In the above commands, these flags are:
-Z-----------Setting up the NC simply scans the listening daemon and does not actually send any data to them.
-v-----------Enable verbose mode
The following command checks to see if ports 80, 22, and 21 are turned on on the remote host 192.168.56.10:
Nc-zv 192.168.56.10 80 22 21
You can also specify the range of port scans:
$ nc-zv 192.168.56.10 20-80
If you need to check whether a port on this machine is open, simply replace the IP address with the local IP, and the port is changed to the port you want to test.
To see if the native port is occupied
Netstat-ap | grep 6380
TCP 0 0 localhost:6380 *:* LISTEN 1280/redis-server 1
tcp 0 0 localhost:16380 *:* LISTEN 1280/redis-server 1