netstat 的一些常用选项
netstat -s本选项能够按照各个协议分别显示其统计数据。如果我们的应用程序(如Web浏览器)运行速度比较慢,或者不能显示Web页之类的数据,那么我们就可以用本选项来查看一下所显示的信息。我们需要仔细查看统计数据的各行,找到出错的关键字,进而确定问题所在。[root@SM155 proc]# netstat -sIp: 8530928 total packets received 0 forwarded 0 incoming packets discarded 6972819 incoming packets delivered 8521573 requests sent out 1 fragments dropped after timeout 39629 reassemblies required 19667 packets reassembled ok 1 packet reassembles failedIcmp: 16023 ICMP messages received 175 input ICMP message failed. ICMP input histogram: destination unreachable: 4362 echo requests: 11661 19476 ICMP messages sent 0 ICMP messages failed ICMP output histogram: destination unreachable: 7815 echo replies: 11661Tcp: 1651264 active connections openings 159526 passive connection openings 197 failed connection attempts 150104 connection resets received 31 connections established 6439010 segments received 6739834 segments send out 423 segments retransmited 0 bad segments received. 1649444 resets sentUdp: 135397 packets received 7341 packets to unknown port received. 0 packet receive errors 1762263 packets sentTcpExt: ArpFilter: 0 800 TCP sockets finished time wait in fast timer 300 time wait sockets recycled by time stamp 8850 delayed acks sent 1 delayed acks further delayed because of locked socket Quick ack mode was activated 12 times 552580 packets directly queued to recvmsg prequeue. 296789 packets directly received from prequeue 724223 packets header predicted 11117 packets header predicted and directly queued to user TCPPureAcks: 249691 TCPHPAcks: 1235152 TCPRenoRecovery: 0 TCPSackRecovery: 1 TCPSACKReneging: 0 TCPFACKReorder: 0 TCPSACKReorder: 0
netstat -e本选项用于显示关于以太网的统计数据。它列出的项目包括传送的数据报的总字节数、错误数、删除数、数据报的数量和广播的数量。这些统计数据既有发送的数据报数量,也有接收的数据报数量。这个选项可以用来统计一些基本的网络流量)。
[root@SM155 proc]# netstat -eActive Internet connections (w/o servers)Proto Recv-Q Send-Q Local Address Foreign Address State User Inode tcp 0 0 10.90.243.155:49182 10.90.243.27:32931 ESTABLISHED root 382858 tcp 0 0 localhost.localdomain:49176 localhost.localdomain:39918 ESTABLISHED root 24542 tcp 1 0 10.90.243.155:64766 10.90.243.27:951 CLOSE_WAIT root 3239351 tcp 0 0 localhost.localdomain:39015 localhost.localdomain:49178 ESTABLISHED root 24546 tcp 0 0 localhost.localdomain:39016 localhost.localdomain:49179 ESTABLISHED root 24548 tcp 0 0 10.90.243.155:ssh 10.88.22.243:3672 ESTABLISHED root 6062002
netstat -r
本选项可以显示关于路由表的信息,类似于后面所讲使用route print命令时看到的 信息。除了显示有效路由外,还显示当前有效的连接。
[root@SM155 proc]# netstat -rKernel IP routing tableDestination Gateway Genmask Flags MSS Window irtt Iface10.90.243.0 * 255.255.255.0 U 0 0 0 eth010.10.10.0 * 255.255.255.0 U 0 0 0 eth1169.254.0.0 * 255.255.0.0 U 0 0 0 eth1default 10.90.243.1 0.0.0.0 UG 0 0 0 eth0[root@SM155 proc]#
本选项显示一个所有的有效连接信息列表,包括已建立的连接(ESTABLISHED),也包括监听连接请(LISTENING)的那些连接。
[root@SM155 proc]# netstat -aActive Internet connections (servers and established)Proto Recv-Q Send-Q Local Address Foreign Address State tcp 0 0 10.90.243.155:39010 *:* LISTEN tcp 0 0 *:shell *:* LISTEN tcp 0 0 10.90.243.155:39011 *:* LISTEN tcp 0 0 *:39012 *:* LISTEN tcp 0 0 *:39015 *:* LISTEN tcp 0 0 *:49159 *:* LISTEN tcp 0 0 localhost.localdomain:39016 *:* LISTEN tcp 0 0 *:49166 *:* LISTEN tcp 0 0 *:39918 *:* LISTEN tcp 0 0 *:sunrpc *:* LISTEN tcp 0 0 *:49173 *:* LISTEN tcp 0 0 *:ftp *:* LISTEN tcp 0 0 *:ssh *:* LISTEN tcp 0 0 *:13819 *:* LISTEN tcp 0 0 *:2812 *:* LISTEN tcp 0 0 10.90.243.155:49182 *:* LISTEN tcp 0 0 10.90.243.155:49182 10.90.243.27:32931 ESTABLISHED tcp 0 0 localhost.localdomain:49176 localhost.localdomain:39918 ESTABLISHED tcp 1 0 10.90.243.155:64766 10.90.243.27:951 CLOSE_WAIT tcp 0 0 localhost.localdomain:39015 localhost.localdomain:49178 ESTABLISHED tcp 0 0 localhost.localdomain:39016 localhost.localdomain:49179 ESTABLISHED
netstat -n
显示所有已建立的有效连接。[root@SM155 proc]# netstat -nActive Internet connections (w/o servers)Proto Recv-Q Send-Q Local Address Foreign Address State tcp 0 0 10.90.243.155:49182 10.90.243.27:32931 ESTABLISHED tcp 0 0 127.0.0.1:49176 127.0.0.1:39918 ESTABLISHED tcp 1 0 10.90.243.155:64766 10.90.243.27:951 CLOSE_WAIT tcp 0 0 127.0.0.1:39015 127.0.0.1:49178 ESTABLISHED tcp 0 0 127.0.0.1:39016 127.0.0.1:49179 ESTABLISHED tcp 0 0 127.0.0.1:39918 127.0.0.1:49176 ESTABLISHED tcp 0 0 10.90.243.155:58692 10.90.243.155:39010 ESTABLISHED tcp 0 0 10.90.243.155:39012 10.90.243.155:49168 ESTABLISHED tcp 0 0 127.0.0.1:39012 127.0.0.1:49174 ESTABLISHED tcp 0 0 10.90.243.155:39012 10.90.243.155:49175 ESTABLISHED tcp 0 0 127.0.0.1:39012 127.0.0.1:49160 ESTABLISHED tcp 0 0 10.90.243.155:39012 10.90.243.155:49161 ESTABLISHED tcp 0 0 127.0.0.1:39012 127.0.0.1:49167 ESTABLISHED tcp 0 0 10.90.243.155:49185 10.90.243.155:39011 ESTABLISHED tcp 0 0 127.0.0.1:49174 127.0.0.1:39012 ESTABLISHED tcp 0 0 10.90.243.155:49175 10.90.243.155:39012 ESTABLISHED tcp 0 0 10.90.243.155:49168 10.90.243.155:39012 ESTABLISHED tcp 0 0 127.0.0.1:49167 127.0.0.1:39012 ESTABLISHED tcp 0 0 127.0.0.1:49160 127.0.0.1:39012 ESTABLISHED tcp 0 0 10.90.243.155:49161 10.90.243.155:39012 ESTABLISHED tcp 0 0 10.90.243.155:49159 10.90.243.155:58726 ESTABLISHED tcp 0 0 127.0.0.1:49178 127.0.0.1:39015 ESTABLISHED