Skillfully use Netstat to eliminate the network fault Chszs, not allowed to reprint without Bo master. Permission to reprint should be marked by the author and blog home: Http://blog.csdn.net/chszs
Ping and traceroute are two common commands when encountering a network failure on a Linux server, but many times you need to know more about the details of the network to help solve the problem. To do this, you can use the Netstat command, which provides detailed information about the network sockets and other useful information. As with the ping and traceroute commands, you can simply use netstat at the command line and get the results immediately.
First, what is netstat
The netstat command is a very useful tool for dealing with network problems. Netstat is the abbreviation for network Statistics, which can display incoming and outgoing network connections, and can also be used to obtain network statistics, protocol statistics, routing table information, and so on.
We can use Netstat to find network problems and measure network traffic, so it can be used to collect network outages, spin down, or network bottlenecks.
Second, the basic netstat
To get a list of all current connections, just use the-a option.
# netstat -aActive Internet connections (servers and established)Proto Recv-Q Send-Q Local Address Foreign Address State tcp 0 0 *:1922 *:* LISTEN tcp 0 216 chdc154:1922 223.99.111.233:11303 ESTABLISHEDtcp6 0 0 [::]:9000 [::]:* LISTEN tcp6 0 0 [::]:8009 [::]:* LISTEN tcp6 0 0 [::]:mysql [::]:* LISTEN tcp6 0 0 [::]:1922 [::]:* LISTEN tcp6 0 0 [::]:9090 [::]:* LISTEN tcp6 0 0 localhost:8005 [::]:* LISTEN ......
It provides basic information about the connections of different types of protocols, such as TCP and UDP, and the active UNIX domain socket information. However, Natstat also allows users to obtain more specific information to help with debugging.
Third, filter by connection type
Filtering results based on connection types can help you find the information you need. For example, if you want to view a TCP connection, you can immediately follow a T option on the-a option above, as follows:
# netstat -aActive Internet connections (servers and established)Proto Recv-Q Send-Q Local Address Foreign Address State tcp 0 0 *:1922 *:* LISTEN tcp 0 216 chdc154:1922 223.99.111.233:11303 ESTABLISHEDtcp6 0 0 [::]:9000 [::]:* LISTEN tcp6 0 0 [::]:8009 [::]:* LISTEN ......
Similarly, if the-a option is followed by the U option, the value lists the UDP connection.
Iv. filtering according to the listening connection
If you want to see the connection you are listening on, you can use the-l option (remove-a option), such as:
# netstat -lActive Internet connections (only servers)......Active UNIX domain sockets (only servers)Proto RefCnt Flags Type State I-Node Pathunix 2 [ ACC ] STREAM LISTENING 47834116 /run/systemd/privateunix 2 [ ACC ] STREAM LISTENING 1661287 /run/user/0/systemd/privateunix 2 [ ACC ] SEQPACKET LISTENING 15450 /run/udev/controlunix 2 [ ACC ] STREAM LISTENING 96528873 /run/snapd-snap.socketunix 2 [ ACC ] STREAM LISTENING 10581 /var/lib/lxd/unix.socketunix 2 [ ACC ] STREAM LISTENING 10578 /run/uuidd/requestunix 2 [ ACC ] STREAM LISTENING 10582 /run/acpid.socket......
Similar to the-a option, the-l option immediately follows the T option, the-LT option, to view the TCP connection being listened to, and-lu to view the TCP connection being listened to. This way, you can easily see if the specified port is open and listening, and determine whether the site app or app is running as expected.
V. Viewing network statistics
# netstat -sIp: 1473970908 total packets received 17795365 with invalid addresses 0 forwarded 0 incoming packets discarded 1453512118 incoming packets delivered 2392531460 requests sent out 40 outgoing packets dropped 3 fragments dropped after timeout 48 reassemblies required 15 packets reassembled ok 3 packet reassembles failedIcmp: 3589646 ICMP messages received 37 input ICMP message failed. ICMP input histogram: destination unreachable: 178 timeout in transit: 18 echo requests: 3589445 echo replies: 5......
As you can see, the-S option provides some statistical information that may be useful when debugging, such as total, incoming and outgoing packets, and ICMP messages that are received, sent, and failed.
Skillfully using Netstat to troubleshoot network problems