list of open ports in ubuntu code example

Example 1: ubuntu listening ports

# To see ports in use
sudo lsof -i -P -n | grep LISTEN 
sudo netstat -tulpn | grep LISTEN

Example 2: list used ports on mac

sudo lsof -PiTCP -sTCP:LISTEN

COMMAND     PID      USER   FD   TYPE             DEVICE SIZE/OFF NODE NAME
GitHub      850 grgarside   6u   IPv4 0x23c345381d089301      0t0  TCP localhost:25035 (LISTEN)

Example 3: linux how to see ports in use

# Any of the following
sudo lsof -i -P -n | grep LISTEN
sudo netstat -tulpn | grep LISTEN
sudo lsof -i:22 # see a specific port such as 22
sudo nmap -sTU -O IP-address-Here

Example 4: ubuntu open all port

sudo ufw allow 1:9999/tcp