View the number of IPs connected to the server
Monitor Server Connections
This guide details how to view various connection details on your Linux server.
Prerequisites:
- Access to your server via SSH client (e.g., Putty)
Steps:
-
Total Connections: Use
netstat -an | wc -l
(faster and cleaner thantoilet
) -
Connections by Port (e.g., Port 80): Use
netstat -an | grep 80 | wc -l
-
Unique Connection Attempts: Use
netstat -ntu | awk '{print $5}' | cut -d: -f1 | sort | uniq -c | sort -n
-
Connections per IP and Port: Use
netstat -na | awk '{print $5}' | cut -d "." -f1,2,3,4 | sort | uniq -c | sort -nr
-
Connections per Port: Use
netstat -tuna | awk -F':+| +' 'NR>2{print $5}' | cut -d: -f1 | sort | uniq -c | sort -n
-
List IPs with Connection Count: Use
netstat -anp | grep 'tcp\|udp' | awk '{print $5}' | cut -d: -f1 | sort | uniq -c | sort -n
By analyzing connection data, you can identify and block suspicious activity.