I have some servers and I want to check which ports are open. Open ports give clue about the load and security about the system. Open ports mean there is services running on the server and clients are using these so a load of this system is generally higher than other servers. Open ports can be used by attackers. Also, open ports will prevent services to use the same port as Nginx and Apache.
Check Open Port With Lsof
We will use lsof
which is a tool to list files, processes and their relevant ports. We will filter lines that contain LISTEN
which is used by open ports.
$ sudo lsof -i -P -n | grep LISTEN
- -i will provide internet protocol related process
- -P will prevent protocol names and use port numbers
- -n will prevent hostnames and use IP addresses

Check Ports With Netstat
netstat
is another useful tool which provides network related information about the host. Following command will check both TCP and UDP ports which are in listen mode or open.
$ sudo netstat -tulpn

Check Ports By Scanning With Nmap
Nmap is a security tool which is used by pentesters and hackers. Nmap is very useful so we can use it to find open ports. Nmap can be used to find open ports on localhost or remote host even on the internet. To get more information about nmap to look at our Nmap Tutorial.
$ sudo nmap -sT -O localhost
