A port scan sends client requests to a server port addresses on a host for finding an active port. The design and operation of the Internet is based on TCP/IP. A port can have some behavior like below:
- Open or Accepted: The host sent a reply indicating that a service is listening on the port.
- Closed or Denied or Not Listening: The host sent a reply indicating that connections will be denied to the port.
- Filtered, Dropped or Blocked: There was no reply from the host.
This is often used by administrators to verify security policies of their networks and can be used by an attacker to identify running services on a host with the view to compromise it.
To find all open/listening ports in your Kali Linux machine, we’ll use Netstat tool which is an open source tool and is already installed in Kali Linux OS. Netstat prints information about the Linux networking subsystem.
According to Wikipedia – Netstat (network statistics) is a command-line network utility tool that displays network connections for the Transmission Control Protocol (both incoming and outgoing), routing tables, and a number of network interface (network interface controller or software-defined network interface) and network protocol statistics.
It is available on Unix-like operating systems including macOS, Linux, Solaris, and BSD, and is available on Windows NT-based operating systems including Windows XP, Windows Vista, Windows 7, Windows 8 and Windows 10.
To find open ports, type the below command in your machine terminal.
Command: sudo netstat -plntu
Where, -p = display PID/Program name for sockets,
-l = display listening server sockets,
-n = don’t resolve names,
-t = tcp ports,
-u = udp ports
As you can see in above screenshot, the port numbers 5432, 5433, 80 and 68 ports are open in which Port 80 is associated with Apache Service and Port 68 is associated with Dhclient Service, and rest all other ports are linked with Postgres service.