runoops.com

Linux netstat命令

Linux netstat 命令用于显示网络状态。

利用 netstat 指令可让你得知整个 Linux 系统的网络情况。

语法

netstat [-acCeFghilMnNoprstuvVwx][-A<网络类型>][--ip]

参数说明

  • -a或--all 显示所有连线中的Socket。
  • -A<网络类型>或--<网络类型> 列出该网络类型连线中的相关地址。
  • -c或--continuous 持续列出网络状态。
  • -C或--cache 显示路由器配置的快取信息。
  • -e或--extend 显示网络其他相关信息。
  • -F或--fib 显示FIB。
  • -g或--groups 显示多重广播功能群组组员名单。
  • -h或--help 在线帮助。
  • -i或--interfaces 显示网络界面信息表单。
  • -l或--listening 显示监控中的服务器的Socket。
  • -M或--masquerade 显示伪装的网络连线。
  • -n或--numeric 直接使用IP地址,而不通过域名服务器。
  • -N或--netlink或--symbolic 显示网络硬件外围设备的符号连接名称。
  • -o或--timers 显示计时器。
  • -p或--programs 显示正在使用Socket的程序识别码和程序名称。
  • -r或--route 显示Routing Table。
  • -s或--statistics 显示网络工作信息统计表。
  • -t或--tcp 显示TCP传输协议的连线状况。
  • -u或--udp 显示UDP传输协议的连线状况。
  • -v或--verbose 显示指令执行过程。
  • -V或--version 显示版本信息。
  • -w或--raw 显示RAW传输协议的连线状况。
  • -x或--unix 此参数的效果和指定"-A unix"参数相同。
  • --ip或--inet 此参数的效果和指定"-A inet"参数相同。

实例

显示详细的网络状况

# netstat -a

显示当前户籍UDP连接状况

# netstat -nu

显示UDP端口号的使用情况

# netstat -apu
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
udp        0      0 0.0.0.0:bootpc          0.0.0.0:*                           904/dhclient
udp        0      0 VM_0_15_centos:ntp      0.0.0.0:*                           633/ntpd
udp        0      0 VM_0_15_centos:ntp      0.0.0.0:*                           633/ntpd
udp6       0      0 VM_0_15_centos:ntp      [::]:*                              633/ntpd
udp6       0      0 VM_0_15_centos:ntp      [::]:*                              633/ntpd

显示网卡列表

# netstat -i
Kernel Interface table
Iface             MTU    RX-OK RX-ERR RX-DRP RX-OVR    TX-OK TX-ERR TX-DRP TX-OVR Flg
eth0             1500 86045182      0      0 0      89822855      0      0      0 BMRU
lo              65536  3191314      0      0 0       3191314      0      0      0 LRU

显示组播组的关系

# netstat -g
IPv6/IPv4 Group Memberships
Interface       RefCnt Group
--------------- ------ ---------------------
lo              1      all-systems.mcast.net
eth0            1      all-systems.mcast.net
lo              1      ff02::1
lo              1      ff01::1
eth0            1      ff02::1:ff13:b681
eth0            1      ff02::1
eth0            1      ff01::1

显示网络统计信息

# netstat -s
Ip:
    87484276 total packets received
    0 forwarded
    0 incoming packets discarded
    84675590 incoming packets delivered
    91678569 requests sent out
    16 dropped because of missing route
    796 reassemblies required
    398 packets reassembled ok
Icmp:
    9595448 ICMP messages received
    251 input ICMP message failed.
    InCsumErrors: 1
    ICMP input histogram:
        destination unreachable: 2045
        timeout in transit: 46
        echo requests: 9593157
        echo replies: 132
        timestamp request: 53
        timestamp reply: 9
    11830537 ICMP messages sent
    0 ICMP messages failed
    ICMP output histogram:
        destination unreachable: 2237327
        echo replies: 9593157
        timestamp replies: 53
IcmpMsg:
        InType0: 132
        InType3: 2045
        InType8: 9593157
        InType11: 46
        InType13: 53
        InType14: 9
        InType165: 5
        OutType0: 9593157
        OutType3: 2237327
        OutType14: 53
Tcp:
    7017843 active connections openings
    2160370 passive connection openings
    31082 failed connection attempts
    31692 connection resets received
    47 connections established
    73150557 segments received
    77004081 segments send out
    1298149 segments retransmited
    57 bad segments received.
    76811 resets sent
Udp:
    1929471 packets received
    89 packets to unknown port received.
    0 packet receive errors
    1979581 packets sent
    0 receive buffer errors
    0 send buffer errors
UdpLite:
TcpExt:
    7258 invalid SYN cookies received
    30255 resets received for embryonic SYN_RECV sockets
    191 packets pruned from receive queue because of socket buffer overrun
    4 ICMP packets dropped because they were out-of-window
    473923 TCP sockets finished time wait in fast timer
    1122 packets rejects in established connections because of timestamp
    4354999 delayed acks sent
    369 delayed acks further delayed because of locked socket
    Quick ack mode was activated 43539 times
    888 SYNs to LISTEN sockets dropped
    1401958 packets directly queued to recvmsg prequeue.
    725175 bytes directly in process context from backlog
    60663 bytes directly received in process context from prequeue
    12848035 packet headers predicted
    289 packets header predicted and directly queued to user
    27900018 acknowledgments not containing data payload received
    6393444 predicted acknowledgments
    22 times recovered from packet loss due to fast retransmit
    33776 times recovered from packet loss by selective acknowledgements
    7 bad SACK blocks received
    Detected reordering 148 times using FACK
    Detected reordering 84 times using SACK
    Detected reordering 385 times using time stamp
    662 congestion windows fully recovered without slow start
    337 congestion windows partially recovered using Hoe heuristic
    2308 congestion windows recovered without slow start by DSACK
    54193 congestion windows recovered without slow start after partial ack
    TCPLostRetransmit: 6904
    8 timeouts after reno fast retransmit
    7294 timeouts after SACK recovery
    5971 timeouts in loss state
    87576 fast retransmits
    9224 forward retransmits
    59651 retransmits in slow start
    575712 other TCP timeouts
    TCPLossProbes: 527038
    TCPLossProbeRecovery: 320985
    9 classic Reno fast retransmits failed
    10573 SACK retransmits failed
    1 times receiver scheduled too late for direct processing
    46999 DSACKs sent for old packets
    981 DSACKs sent for out of order packets
    331457 DSACKs received
    98 DSACKs for out of order packets received
    5562 connections reset due to unexpected data
    7135 connections reset due to early user close
    8364 connections aborted due to timeout
    TCPSACKDiscard: 27
    TCPDSACKIgnoredOld: 21
    TCPDSACKIgnoredNoUndo: 236533
    TCPSpuriousRTOs: 1654
    TCPSackShiftFallback: 237468
    TCPRcvCoalesce: 8730449
    TCPOFOQueue: 369700
    TCPOFOMerge: 1804
    TCPChallengeACK: 2351
    TCPSYNChallenge: 131
    TCPFastOpenCookieReqd: 10
    TCPSpuriousRtxHostQueues: 1570
    TCPFromZeroWindowAdv: 8
    TCPToZeroWindowAdv: 8
    TCPWantZeroWindowAdv: 288
    TCPSynRetrans: 459990
    TCPOrigDataSent: 38844156
    TCPHystartTrainDetect: 90
    TCPHystartTrainCwnd: 2776
    TCPHystartDelayDetect: 164
    TCPHystartDelayCwnd: 7097
    TCPACKSkippedSynRecv: 477
    TCPACKSkippedPAWS: 150
    TCPACKSkippedSeq: 1364
    TCPACKSkippedTimeWait: 89
    TCPACKSkippedChallenge: 37
IpExt:
    InNoRoutes: 5
    InMcastPkts: 200627
    InOctets: 8033825866
    OutOctets: 15832341267
    InMcastOctets: 7222572
    InNoECTPkts: 87780970
    InECT1Pkts: 256
    InECT0Pkts: 102401
    InCEPkts: 21831

显示监听的套接口

# netstat -l
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State
tcp        0      0 0.0.0.0:cddbp           0.0.0.0:*               LISTEN
tcp        0      0 VM_0_15_centos:smtp     0.0.0.0:*               LISTEN
tcp        0      0 0.0.0.0:sunwebadmins    0.0.0.0:*               LISTEN
tcp        0      0 0.0.0.0:http            0.0.0.0:*               LISTEN
tcp        0      0 0.0.0.0:ftp             0.0.0.0:*               LISTEN
tcp        0      0 0.0.0.0:ssh             0.0.0.0:*               LISTEN
tcp6       0      0 VM_0_15_centos:smtp     [::]:*                  LISTEN
tcp6       0      0 [::]:mysql              [::]:*                  LISTEN
tcp6       0      0 [::]:ftp                [::]:*                  LISTEN
udp        0      0 0.0.0.0:bootpc          0.0.0.0:*
udp        0      0 VM_0_15_centos:ntp      0.0.0.0:*
udp        0      0 VM_0_15_centos:ntp      0.0.0.0:*
udp        0      0 0.0.0.0:56631           0.0.0.0:*
udp6       0      0 VM_0_15_centos:ntp      [::]:*
udp6       0      0 VM_0_15_centos:ntp      [::]:*
Active UNIX domain sockets (only servers)
Proto RefCnt Flags       Type       State         I-Node   Path
unix  2      [ ACC ]     STREAM     LISTENING     10758    /run/lvm/lvmetad.socket
unix  2      [ ACC ]     STREAM     LISTENING     7457     /run/systemd/journal/stdout
unix  2      [ ACC ]     STREAM     LISTENING     38969    public/pickup
unix  2      [ ACC ]     STREAM     LISTENING     38973    public/cleanup
...