
{{ $('Map tags to IDs').item.json.title }}
How to Monitor Network Traffic with netstat
netstat (network statistics) is a command-line tool used to display network connections, routing tables, interface statistics, and other network-related information. It is particularly useful for monitoring network traffic and connections on your system. This tutorial will provide an overview of the netstat command and its usage.
1. Installing netstat
Most Linux distributions come with netstat pre-installed as part of the net-tools package. You can check if netstat is available by running:
netstat --version
If it’s not installed, you can install it using:
- For Ubuntu:
sudo apt install net-tools
- For CentOS:
sudo yum install net-tools
2. Viewing Active Connections
To view all active Network connections, run:
netstat -a
The -a
option displays listening and non-listening sockets, along with their states (e.g., ESTABLISHED, LISTENING).
3. Monitoring Network Interfaces
To display statistics about your network interfaces (such as packets received and sent), use:
netstat -i
4. Displaying Routing Table
To view your routing table, run:
netstat -r
This will show the current routes used by the kernel to forward packets.
5. Monitoring Network Connections with Process IDs
To show which processes are using the network ports, use:
netstat -tulnp
Here, -t
displays TCP connections, -u
shows UDP connections, -l
shows listening sockets, -n
shows numerical addresses, and -p
shows the PID and name of the program to which each socket belongs.
6. Filtering Results
To filter the results, you can use tools like grep
. For example, to show only established connections:
netstat -at | grep ESTABLISHED
7. Conclusion
Using the netstat command, you can effectively monitor network traffic and manage connections on your Linux system. It provides valuable insights into the network activity, helping you troubleshoot and optimize performance. Explore additional options and flags within netstat to enhance your network monitoring capabilities!