Viewing open ports in Linux can be accomplished using several tools and methods. Some commonly used tools include netstat, ss, and nmap. Here's how you can use these tools to see open ports:
Using netstat
netstat is a widely used network utility for checking active connections and listening ports.
Install netstat (if not already installed):
sudo apt update
sudo apt install net-tools
View Open Ports:
sudo netstat -tuln
-t : Show TCP ports.
-u : Show UDP ports.
-l : Show listening ports.
-n : Show numerical addresses.
Using ss
ss (Socket Statistics) is a modern replacement for netstat and provides more detailed information.
View Open Ports:
sudo ss -tuln
-t : Show TCP ports.
-u : Show UDP ports.
-l : Show listening ports.
-n : Show numerical addresses.
Using nmap
nmap (Network Mapper) is a powerful tool for network discovery and security auditing. It can be used to scan for open ports on a machine.
Install nmap (if not already installed):
sudo apt update
sudo apt install nmap
Scan for Open Ports on Local Machine:
sudo nmap -sT -O localhost
-sT : TCP connect scan.
-O : Enable OS detection.
Scan a Specific IP Address or Host:
sudo nmap -sT -O 192.168.1.1
Using lsof
lsof (List Open Files) can also be used to identify open ports.
Install lsof (if not already installed):
sudo apt update
sudo apt install lsof
View Open Internet Files (Ports):
sudo lsof -i -P -n | grep LISTEN
-i : Selects the listing of files any of whose Internet address matches the address specified.
-P : Inhibits the conversion of port numbers to port names.
-n : Inhibits the conversion of network numbers to host names.
Note that using sudo may be necessary to see all open ports, especially those opened by system services. The choice of tool can depend on your specific needs and what details you wish to see.