The netstat command is a useful tool for monitoring TCP/IP networks. It displays the route table, the actual network connection, and the status information of each network interface device. The following describes the implementation of the Linux testing tool netstat.
After running the Linux test tool netstat on a computer, the output result is as follows:
- [root@lee /root]#netstat
- Active Internet connections (w/o servers)
- Proto Recv-Q Send-Q Local Address Foreign Address State
- Active UNIX domain sockets (w/o servers)
- Proto RefCnt Flags Types State I-Node Path
- Unix 5 [ ] DGRAM 460 /dev/log
- Unix 0 [ ] STREAM CONNECTED 173 @00000014
- Unix 0 [ ] DGRAM 662
- Unix 0 [ ] DGRAM 631
- Unix 0 [ ] DGRAM 544
- Unix 0 [ ] DGRAM 484
- Unix 0 [ ] DGRAM 470
- [root@lee /root]#
As a whole, the output result of the Linux test tool netstat can be divided into two parts: the first part is Active Internet connections, which is called an Active TCP connection. In the output result above, this part has no content, indicating that there is no TCP connection. The second part is Active UNIX domain sockets, which is called the interface of the Active Unix domain. The output shows the connection of the Unix domain interface:
◆ Proto displays the protocol used by the connection.
◆ RefCnt indicates the process number connected to this interface.
◆ Type of the Types display set interface.
◆ State: displays the current status of the Set interface.
◆ Path indicates the Path name used by other processes connected to the set interface.
You can use Linux testing tool netstat-a to view the status of all sockets, which is very useful when you debug network programs. The Linux test tool netstat-r will display the contents of the route table. Generally, you must specify the "-n" option at the same time to obtain the address in digital format or the IP address of the default router. Using the Linux test tool netstat-I will display all network interface information. The Linux testing tool netstat can also obtain the current network status and network topology, which is very useful in practice.