I have some servers and I want to check which ports is 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 the load of this system is generally higher than other servers. Open ports can be used by attackers. Also open ports will prevent services use same port like 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 those contains
LISTEN which is used by open ports.
$ sudo lsof -i -P -n | grep LISTEN
- -i will provides 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 an other useful tool which provides network related information about 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 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 in local host or remote host even on the internet. To get more information about nmap look our Nmap Tutorial.
$ sudo nmap -sT -O localhost