首页 > 代码库 > netstat

netstat

Netstat简介

Netstat 命令用于显示各种网络相关信息,如网络连接,路由表,接口状态 (Interface Statistics),masquerade 连接,多播成员 (Multicast Memberships) 等等。

参数如下:

[root@rhel6 script]# netstat --help
usage: netstat [-veenNcCF] [<Af>] -r         netstat {-V|--version|-h|--help}
       netstat [-vnNcaeol] [<Socket> ...]
       netstat { [-veenNac] -I[<Iface>] | [-veenNac] -i | [-cnNe] -M | -s } [delay]

        -r, --route                display routing table
        -I, --interfaces=<Iface>   display interface table for <Iface>
        -i, --interfaces           display interface table
        -g, --groups               display multicast group memberships
        -s, --statistics           display networking statistics (like SNMP)
        -M, --masquerade           display masqueraded connections

        -v, --verbose              be verbose
        -n, --numeric              dont resolve names
        --numeric-hosts            dont resolve host names
        --numeric-ports            dont resolve port names
        --numeric-users            dont resolve user names
        -N, --symbolic             resolve hardware names
        -e, --extend               display other/more information
        -p, --programs             display PID/Program name for sockets
        -c, --continuous           continuous listing

        -l, --listening            display listening server sockets
        -a, --all, --listening     display all sockets (default: connected)
        -o, --timers               display timers
        -F, --fib                  display Forwarding Information Base (default)
        -C, --cache                display routing cache instead of FIB
        -T, --notrim               stop trimming long addresses
        -Z, --context              display SELinux security context for sockets

常见参数

-r, --route    display routing table

-i, --interfaces  interface table

-s, --statistics  display networking statistics (like SNMP)

-l, --listening    display listening server sockets

-p, --programs     display PID/Program name for sockets

-n             拒绝显示别名,能显示数字的全部转化成数字。

-t (tcp)          仅显示tcp相关选项
-u (udp)        仅显示udp相关选项

 

应用实例

netstat -lntup

[root@rhel6 script]# netstat -lntup
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address               Foreign Address             State       PID/Program name   
tcp        0      0 0.0.0.0:5053                0.0.0.0:*                   LISTEN      1727/ovtrcd         
tcp        0      0 0.0.0.0:3306                0.0.0.0:*                   LISTEN      16463/mysqld        
tcp        0      0 0.0.0.0:111                 0.0.0.0:*                   LISTEN      1563/rpcbind        
tcp        0      0 0.0.0.0:46067               0.0.0.0:*                   LISTEN      1585/rpc.statd      
tcp        0      0 0.0.0.0:22                  0.0.0.0:*                   LISTEN      1684/sshd           
tcp        0      0 :::54472                    :::*                        LISTEN      1585/rpc.statd      
tcp        0      0 :::111                      :::*                        LISTEN      1563/rpcbind        
tcp        0      0 :::22                       :::*                        LISTEN      1684/sshd           
udp        0      0 0.0.0.0:111                 0.0.0.0:*                               1563/rpcbind        
udp        0      0 0.0.0.0:890                 0.0.0.0:*                               1563/rpcbind        
udp        0      0 10.120.4.90:123             0.0.0.0:*                               1695/ntpd           
udp        0      0 127.0.0.1:123               0.0.0.0:*                               1695/ntpd           
udp        0      0 0.0.0.0:123                 0.0.0.0:*                               1695/ntpd           
udp        0      0 127.0.0.1:914               0.0.0.0:*                               1585/rpc.statd      
udp        0      0 0.0.0.0:45849               0.0.0.0:*                               1585/rpc.statd      
udp        0      0 :::111                      :::*                                    1563/rpcbind        
udp        0      0 :::890                      :::*                                    1563/rpcbind        
udp        0      0 :::123                      :::*                                    1695/ntpd           
udp        0      0 :::58040                    :::*                                    1585/rpc.statd      
[root@rhel6 script]# 

netstat -r

[root@rhel6 script]# netstat -r
Kernel IP routing table
Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface
10.120.4.0      *               255.255.255.0   U         0 0          0 eth0
link-local      *               255.255.0.0     U         0 0          0 eth0
default         10.120.4.1      0.0.0.0         UG        0 0          0 eth0
[root@rhel6 script]# 

netstat -s

[root@rhel6 script]# netstat -s
Ip:
    2049877 total packets received
    60418 with invalid addresses
    0 forwarded
    0 incoming packets discarded
    1989459 incoming packets delivered
    1981406 requests sent out
    12474 outgoing packets dropped
Icmp:
    162525 ICMP messages received
    0 input ICMP message failed.
    ICMP input histogram:
        destination unreachable: 162522
        echo requests: 3
    162525 ICMP messages sent
    0 ICMP messages failed
    ICMP output histogram:
        destination unreachable: 162522
        echo replies: 3
IcmpMsg:
        InType3: 162522
        InType8: 3
        OutType0: 3
        OutType3: 162522
Tcp:
    163249 active connections openings
    163186 passive connection openings
    58 failed connection attempts

netstat -i

[root@rhel6 script]# netstat -i
Kernel Interface table
Iface       MTU Met    RX-OK RX-ERR RX-DRP RX-OVR    TX-OK TX-ERR TX-DRP TX-OVR Flg
eth0       1500   0   527179      0      0      0    25253      0      0      0 BMRU
lo        65536   0  1957492      0      0      0  1957492      0      0      0 LRU
[root@rhel6 script]# 

 

netstat