sudo netstat -tulnp
- `-t` - show TCP ports
- `-u` - show UDP ports
- `-l` - show listening ports
- `-n` - show numeric addresses instead of resolving hostnames
- `-p` - show the process using the port
sudo ss -tulnp
Same options as netstat, but generally faster.
sudo lsof -i -P -n | grep LISTEN
- `-i` - show network connections
- `-P` - show port numbers instead of service names
- `-n` - show numeric addresses
sudo lsof -i :22 # Check if port 22 is open
nmap -sT -O localhost
Or to scan a remote host:
nmap target-ip-address
sudo iptables -L -n -v # For iptables
sudo ufw status verbose # For UFW (Ubuntu)
sudo firewall-cmd --list-all # For firewalld (RHEL/CentOS/Fedora)
Note that you'll typically need root privileges (using sudo) to see all open ports and the processes using them.
For port 3000 as an example:
sudo kill $(sudo lsof -t -i:3000)
Or more forcefully:
sudo kill -9 $(sudo lsof -t -i:3000)