📊 Viewing Network Statistics
Once your network is up and you can download files or ping other machines, it's important to see what's happening under the hood. Linux gives us tools like netstat and ss for this. Think of them like a dashboard showing all traffic and connections to your computer.
Using netstat
This command shows all active network connections and listening ports. The flags are:
- -t → TCP connections
- -u → UDP connections
- -l → listening ports
- -n → show numeric addresses (don't resolve names)
Proto Recv-Q Send-Q Local Address Foreign Address State tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN udp 0 0 0.0.0.0:68 0.0.0.0:*
In the output, 0.0.0.0:22 means your machine is listening for SSH connections on port 22. The State LISTEN means the port is ready to accept connections.
Using ss (Socket Statistics)
ss is the modern replacement for netstat. It's faster and more detailed, showing sockets, connections, listening ports, etc.
Netid State Recv-Q Send-Q Local Address:Port Peer Address:Port tcp LISTEN 0 128 0.0.0.0:22 0.0.0.0:* udp UNCONN 0 0 0.0.0.0:68 0.0.0.0:*
Quick Tips
This shows a summary of socket usage.
This shows which process is using each connection.
Real-life analogy
For netstat: It's like checking which doors of your house are open and which friends are currently visiting. For ss: Think of it as a real-time CCTV of your network doors and current traffic — it's faster and more modern than the old netstat. This topic is crucial because it lets you monitor network activity, troubleshoot issues, and see open ports, which is super important for security and system management.