Sobes.tech
Junior

How to view open ports on a machine?

sobes.tech AI

Answer from AI

  • netstat -tulnp - Show TCP and UDP sockets listening on ports, with PID and process name.
  • ss -tulnp - Similar to netstat, but faster and recommended for modern systems.
  • lsof -i -P -n - List open internet files, including listening ports.
  • nmap localhost or nmap 127.0.0.1 - Scan the local machine for open ports.

Usage examples:

# View listening TCP ports with PID
netstat -tulpn | grep LISTEN
# View listening ports for a specific process (e.g., Nginx)
ss -tulnp | grep nginx
# Find process using port 8080
lsof -i :8080
# Scan local host for open ports using nmap
nmap 127.0.0.1

Standard tools:

Command Purpose
netstat Network statistics
ss Socket statistics
lsof List open files
nmap Port and network scanner