Practical Netstat Usage Examples
Listing All Active Network Connections
To list all active network connections, including both incoming and outgoing connections, use the following command:
netstat -antp
This will display a table with the protocol, local and foreign addresses, connection state, and the associated process information.
Listing TCP Connections
To list only the active TCP connections, use the following command:
netstat -antp --tcp
Listing UDP Connections
To list only the active UDP connections, use the following command:
netstat -antp --udp
Listing Listening Ports
To list all the ports that are in the "LISTEN" state, indicating that they are listening for incoming connections, use the following command:
netstat -antp --listening
Listing Connections by Process
To list the network connections associated with a specific process, use the following command:
netstat -antp --program | grep "process_name"
Replace "process_name"
with the name of the process you want to investigate.
Monitoring Network Activity in Real-Time
To monitor network activity in real-time, you can use the watch
command along with netstat
:
watch -n 1 "netstat -antp"
This will update the netstat
output every second, allowing you to observe changes in network connections in real-time.
By using these practical examples, you can effectively utilize the netstat
command to identify active network connections, troubleshoot network-related issues, and gain insights into your system's network behavior.