netstat


• Print network connections, routing tables, interface statistics, masquerade connections, and multicast memberships

All Ports (Established + Listen)



# o - show timers; n - port number; p - show pid / program name
sudo netstat -aon | less
sudo netstat -ao | less

sudo netstat -atp | less                # tcp only
sudo netstat -aup | less                # udp only


All Ports (Listen)



sudo netstat -atp | grep -i listen      # tcp
sudo netstat -ltp

sudo netstat -aup | grep -i listen      # udp
sudo netstat -lup


Refresh Established Connections Continously

sudo netstat -apc | grep -i esta
sudo watch -d -n0 "netstat -atp | grep ESTA"        # better

# Display IP address of high number of connections on port 80
sudo netstat -tn 2>/dev/null | grep :80 | awk '{print $5}' | cut -d: -f1 | sort | uniq -c | sort -rn | head

# Display IP address connected to port 80
sudo netstat -tn 2>/dev/null | grep :80 | awk '{print $5}' | sed -e 's/::ffff://' | cut -f1 -d: | sort | uniq -c | sort -rn | head

# Display remote IP address with port 80
sudo netstat -antu | grep :80 | grep -v LISTEN | awk '{print $5}'


Show IP Routing Table

sudo netstat -r

Index