netstat command in Linux is used to display network statistics and information about network connections, routing tables, and network interfaces on a system. It provides valuable insights into network activities and helps troubleshoot network-related issues.
Here’s an overview of how to use the
- Displaying Network Connections:
To display active network connections, use the following syntax:
This command shows all TCP (
-t) and UDP (
-u) connections with their respective ports (
-n) and listening (
- Displaying Network Interfaces:
To display information about network interfaces, use the following syntax:
This command lists all network interfaces along with their associated statistics, such as packets and errors.
- Displaying Routing Table:
To display the routing table, use the following syntax:
This command shows the routing table, including destination networks, gateways, and interface information.
- Displaying Network Statistics:
To display general network statistics, use the following syntax:
This command provides detailed statistics about different network protocols, including TCP, UDP, IP, and ICMP.
- Filtering Output:
You can filter the output of
netstatusing various options. Some commonly used options include:
- Filtering by Protocol: Use
-ufor UDP, and
-pfollowed by the protocol name to filter by a specific protocol.
- Filtering by Port: Use
-pfollowed by the port number to filter by a specific port.
- Filtering by IP Address: Use
-nto display IP addresses instead of hostnames and use
-sfollowed by the IP address to filter by a specific IP.
- Display all active TCP and UDP connections:
- Display network interfaces and their statistics:
- Display the routing table:
- Display network statistics for all protocols:
- Filter output to display TCP connections on a specific port (e.g., port 80):
netstat -tuln | grep :80
- Filter output to display connections associated with a specific IP address (e.g., 192.168.0.1):
netstat -tuln | grep 192.168.0.1
netstat command is a versatile tool for examining network connections, interfaces, routing tables, and statistics. It helps administrators monitor network activities, identify network-related issues, and analyze network performance.
For more information about the
netstat command and its options, you can refer to the manual page by typing
man netstat in your terminal.