3 ways to know listening ports in linux
1.lsof
Ls = list(linux everything is ba file)
-i option = Internet and network files,
sudo lsof -i -P -n | grep LISTEN
sudo lsof -i :80
2.Nestat
Nestat depricated
netstat -tulpn | grep LISTEN
Grep means search
sudo ss -tulw
sudo ss -tulwn
-
-t : Show only TCP sockets on Linux
-
-u : Display only UDP sockets on Linux
-
-l : Show listening sockets. For example, port 22 by SSHD server . 3306 MySQL port 80 web, 443 SSL.
-
-p : List process name that opened sockets(printing program)
-
-n : Don’t resolve service names i.e. don’t use DNS
Process id, port, listening up address, application name, process id of the application.
sudo netstat -lntup | grep “nginx/apache2”
sudo netstat -lntup | grep “80”
3.nmap command
sudo apt install nmap
sudo nmap -sT -O localhost
$ sudo nmap -sU -O localhost
sudo nmap -sTU -O localhost
T: TCP
U: UDP
To know listening ports in Windows
netstat -bano | grep LISTENING
Blocked ports
All ports