Skip to content

Checking Unix Ports

Port ranges

  • Reserved/trusted ports jkinclude 0 -- 1023
  • Registered Ports include 1024 -- 49151
  • Dynamic and private ports include 49152 -- 65535

See the /etc/services file for a small local database containing well-known ports

Checking Open Ports

There are a number of ways to check open ports, including with the commands ss, lsof, netstat, and nmap. Below are a few examples

sh
sudo lsof -i -P -n | grep LISTEN  # <- My favourite
sudo netstat -tulpn | grep LISTEN
sudo ss -tulpn
sudo nmap -sTU -O localhost
sudo lsof -i -P -n | grep LISTEN  # <- My favourite
sudo netstat -tulpn | grep LISTEN
sudo ss -tulpn
sudo nmap -sTU -O localhost

Scan a Port

Use nmap to scan a specific port and get details on it

sh
nmap -p <host_port> <host_address>
nmap -p <host_port> <host_address>

Show Firewall Rules

Use the iptables (or ip6tables) command to view firewall rules

sh
sudo iptables -S
sudo iptables -S

ADDITIONAL RESOURCES