Linux shell netstat 命令

返回上一级

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

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

netstat 命令语法格式

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 , --statistice
显示网络工作信息统计表。
-t , --tcp
显示TCP传输协议的连线状况。
-u , --udp
显示UDP传输协议的连线状况。
-v , --verbose
显示指令执行过程。
-V , --version
显示版本信息。
-w , --raw
显示RAW传输协议的连线状况。
-x , --unix
此参数的效果和指定"-A unix"参数相同。
--ip , --inet
此参数的效果和指定"-A inet"参数相同。

范例

范例 1 : 显示详细的网络状况

[root@localhost ~]# netstat -a
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address           Foreign Address         State
tcp        0      0 0.0.0.0:ssh             0.0.0.0:*               LISTEN
tcp        0      0 localhost:smtp          0.0.0.0:*               LISTEN
tcp        0      0 localhost.localdoma:ssh 192.168.0.100:64504     ESTABLISHED
tcp6       0      0 [::]:ssh                [::]:*                  LISTEN
tcp6       0      0 [::]:telnet             [::]:*                  LISTEN
tcp6       0      0 localhost:smtp          [::]:*                  LISTEN
udp        0      0 0.0.0.0:bootpc          0.0.0.0:*
udp        0      0 0.0.0.0:23698           0.0.0.0:*
udp6       0      0 [::]:62067              [::]:*
Active UNIX domain sockets (servers and established)
Proto RefCnt Flags       Type       State         I-Node   Path
unix  2      [ ]         DGRAM                    8466     /run/systemd/notify

....

范例 2 : 显示当前用户 UDP 连接状况

[root@localhost ~]# netstat -nu
Active Internet connections (w/o servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State
[root@localhost ~]#

范例 3 : 显示UDP端口号的使用情况

[root@localhost ~]# 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:*                           792/dhclient
udp        0      0 0.0.0.0:23698           0.0.0.0:*                           792/dhclient
udp6       0      0 [::]:62067              [::]:*                              792/dhclient
[root@localhost ~]#

范例 4 : 显示网卡列表

[root@localhost ~]# netstat -i
Kernel Interface table
Iface      MTU    RX-OK RX-ERR RX-DRP RX-OVR    TX-OK TX-ERR TX-DRP TX-OVR Flg
ens33     1500      147      0      0 0            94      0      0      0 BMRU
lo       65536        0      0      0 0             0      0      0      0 LRU
[root@localhost ~]#

范例 4 : 显示组播组的关系

[root@localhost ~]# netstat -g
IPv6/IPv4 Group Memberships
Interface       RefCnt Group
--------------- ------ ---------------------
lo              1      all-systems.mcast.net
ens33           1      all-systems.mcast.net
lo              1      ff02::1
lo              1      ff01::1
ens33           1      ff02::1:ff0c:6d90
ens33           1      ff02::1
ens33           1      ff01::1
[root@localhost ~]#

范例 5 : 显示网络统计信息

[root@localhost ~]# netstat -s
Ip:
    169 total packets received
    0 forwarded
    0 incoming packets discarded
    157 incoming packets delivered
    91 requests sent out
Icmp:
    19 ICMP messages received
    1 input ICMP message failed.
    ICMP input histogram:
        redirects: 19
    0 ICMP messages sent
    0 ICMP messages failed
    ICMP output histogram:
IcmpMsg:
        InType5: 19
Tcp:
    0 active connections openings
    1 passive connection openings
    0 failed connection attempts
    0 connection resets received
    1 connections established
    126 segments received
    83 segments send out
    1 segments retransmited
    0 bad segments received.
    1 resets sent
Udp:
    12 packets received
    0 packets to unknown port received.
    0 packet receive errors
    12 packets sent
    0 receive buffer errors
    0 send buffer errors
UdpLite:
TcpExt:
    13 ICMP packets dropped because socket was locked
    3 delayed acks sent
    1 packet headers predicted
    68 acknowledgments not containing data payload received
    6 predicted acknowledgments
    TCPLossProbes: 1
    1 DSACKs received
    IPReversePathFilter: 2
    TCPOrigDataSent: 73
    TCPHystartTrainDetect: 1
    TCPHystartTrainCwnd: 17
IpExt:
    InBcastPkts: 10
    InOctets: 16918
    OutOctets: 22030
    InBcastOctets: 1450
    InNoECTPkts: 169
[root@localhost ~]#

范例 6 : 显示监听的套接口

[root@localhost ~]# netstat -l
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State
tcp        0      0 0.0.0.0:ssh             0.0.0.0:*               LISTEN
tcp        0      0 localhost:smtp          0.0.0.0:*               LISTEN
tcp6       0      0 [::]:ssh                [::]:*                  LISTEN
tcp6       0      0 [::]:telnet             [::]:*                  LISTEN
tcp6       0      0 localhost:smtp          [::]:*                  LISTEN
udp        0      0 0.0.0.0:bootpc          0.0.0.0:*
udp        0      0 0.0.0.0:23698           0.0.0.0:*
udp6       0      0 [::]:62067              [::]:*
Active UNIX domain sockets (only servers)
Proto RefCnt Flags       Type       State         I-Node   Path
unix  2      [ ACC ]     STREAM     LISTENING     8482     /run/systemd/journal/stdout
unix  2      [ ACC ]     STREAM     LISTENING     18228    /var/run/NetworkManager/private-dhcp
unix  2      [ ACC ]     STREAM     LISTENING     15685    /var/run/dbus/system_bus_socket
unix  2      [ ACC ]     STREAM     LISTENING     12918    /run/systemd/private
unix  2      [ ACC ]     STREAM     LISTENING     16524    /var/run/vmware/guestServicePipe
unix  2      [ ACC ]     STREAM     LISTENING     12941    /run/lvm/lvmpolld.socket
unix  2      [ ACC ]     STREAM     LISTENING     12952    /run/lvm/lvmetad.socket
unix  2      [ ACC ]     STREAM     LISTENING     19673    private/verify
unix  2      [ ACC ]     STREAM     LISTENING     19679    private/proxymap
unix  2      [ ACC ]     STREAM     LISTENING     19682    private/proxywrite
unix  2      [ ACC ]     STREAM     LISTENING     19685    private/smtp
unix  2      [ ACC ]     STREAM     LISTENING     19688    private/relay
unix  2      [ ACC ]     STREAM     LISTENING     19694    private/error
unix  2      [ ACC ]     STREAM     LISTENING     19697    private/retry
unix  2      [ ACC ]     STREAM     LISTENING     19700    private/discard
unix  2      [ ACC ]     STREAM     LISTENING     19703    private/local
unix  2      [ ACC ]     STREAM     LISTENING     19706    private/virtual
unix  2      [ ACC ]     STREAM     LISTENING     19709    private/lmtp
unix  2      [ ACC ]     STREAM     LISTENING     19712    private/anvil
unix  2      [ ACC ]     STREAM     LISTENING     19715    private/scache
unix  2      [ ACC ]     STREAM     LISTENING     19658    private/tlsmgr
unix  2      [ ACC ]     STREAM     LISTENING     19670    private/trace
unix  2      [ ACC ]     STREAM     LISTENING     19661    private/rewrite
unix  2      [ ACC ]     STREAM     LISTENING     19647    public/pickup
unix  2      [ ACC ]     STREAM     LISTENING     19664    private/bounce
unix  2      [ ACC ]     STREAM     LISTENING     19651    public/cleanup
unix  2      [ ACC ]     STREAM     LISTENING     19654    public/qmgr
unix  2      [ ACC ]     STREAM     LISTENING     19676    public/flush
unix  2      [ ACC ]     STREAM     LISTENING     19667    private/defer
unix  2      [ ACC ]     STREAM     LISTENING     19691    public/showq
unix  2      [ ACC ]     SEQPACKET  LISTENING     13026    /run/udev/control

返回上一级

Linux Shell 命令大全

关于   |   FAQ   |   我们的愿景   |   广告投放   |  博客

  简单教程,简单编程 - IT 入门首选站

Copyright © 2013-2022 简单教程 twle.cn All Rights Reserved.