Flash Sale:75% Off Hosting + Free DomainEnds in13h47m14sView Plans
Hostvento logoHostvento

Check Open Ports on Linux

See which ports listen on your server and which program uses them. Use ss, lsof, netstat or nmap.

Firewall2 min read13 screenshots

What an open port is

A port is a numbered door for network traffic. A service listens on a port and waits for connections. A web server uses port 80 and 443, SSH uses 22.

  • TCP checks that every packet arrives, in the right order.
  • UDP is fast but does not check delivery. DNS and streaming use it.

Check your open ports from time to time. Close the ones you do not need.

Method 1: ss

ss is the modern replacement of netstat.

List all listening ports

ss -tuln
All listening ports with ss

-t is TCP, -u is UDP, -l is listening, -n shows numbers and not names.

Show the program for each port

sudo ss -tulnp
Listening ports with the process name

Only TCP or only UDP

ss -tln
ss -uln
Only TCP ports
Only UDP ports

Method 2: lsof

All listening ports

sudo lsof -i -P -n
Network connections shown by lsof

One port

sudo lsof -i :80
Who uses port 80

Only TCP listeners

sudo lsof -iTCP -sTCP:LISTEN -P -n
TCP listeners with lsof

Only UDP

sudo lsof -iUDP -P -n
UDP ports with lsof

Method 3: netstat

If netstat is missing, install the net-tools package.

netstat -tuln
Listening ports with netstat

Add -p to see the program names (needs sudo):

sudo netstat -tulnp
Ports and programs with netstat

Method 4: nmap

nmap scans a host from the outside view. Install it:

sudo apt install nmap
Installing nmap

Scan your own machine:

nmap localhost
Scanning localhost

Check one port:

nmap -p 80 localhost
Scanning port 80
Warning: Scan only systems that you own or that you are allowed to test.

Quick recap

  • sudo ss -tulnp is the best first command.
  • lsof -i :PORT shows who uses one port.
  • nmap shows what an outside scan sees.