Linux中的netstat命令

最近因为一个端口问题搞得挺恼火的,在解决问题的过程中又用了不少netstat命令,那么借此机会就再复习一下netstat在几种常用参数下的用法吧。

显示所有监听和非监听的套接字

$ netstat -a

显示所有TCP端口,t就是TCP,下同

$ netstat -at

显示所有UDP端口,u就是UDP,下同

$ netstat -au

列出只监听的端口

$ netstat -l

列出只监听的TCP端口

$ netstat -lt

列出只监听的UDP端口

$ netstat -lu

显示统计信息,s参数是statistics

$ netstat -s
Ip:
    383 total packets received
    3 with invalid addresses
    0 forwarded
    0 incoming packets discarded
    380 incoming packets delivered
    351 requests sent out
    40 outgoing packets dropped
Icmp:
    81 ICMP messages received
    0 input ICMP message failed.
    ICMP input histogram:
        destination unreachable: 80
        echo requests: 1
    81 ICMP messages sent
    0 ICMP messages failed
    ICMP output histogram:
        destination unreachable: 80
        echo replies: 1
IcmpMsg:
        InType3: 80
        InType8: 1
        OutType0: 1
        OutType3: 80
Tcp:
    1 active connections openings
    1 passive connection openings
    0 failed connection attempts
    0 connection resets received
    1 connections established
    180 segments received
    172 segments send out
    0 segments retransmited
    0 bad segments received.
    0 resets sent
Udp:
    18 packets received
    80 packets to unknown port received.
    0 packet receive errors
    99 packets sent
    IgnoredMulti: 21
UdpLite:
TcpExt:
    7 delayed acks sent
    75 packet headers predicted
    32 acknowledgments not containing data payload received
    79 predicted acknowledgments
    TCPLossProbes: 1
    TCPRcvCoalesce: 3
    TCPAutoCorking: 6
    TCPOrigDataSent: 146
IpExt:
    InBcastPkts: 21
    InOctets: 29819
    OutOctets: 41669
    InBcastOctets: 1638
    InNoECTPkts: 384

显示PID以及程序的名字

$ netstat -pt

持续打印netstat信息,c是continuously

$ netstat -c

内核路由信息

$ netstat -r

获取正在运行的程序的端口

$ netstat -ap | grep ssh
(Not all processes could be identified, non-owned process info
 will not be shown, you would have to be root to see it all.)
tcp        0      0 *:ssh                   *:*                     LISTEN      -               
tcp        0      0 192.168.240.134:ssh     192.168.240.1:52017     ESTABLISHED -               
tcp6       0      0 [::]:ssh                [::]:*                  LISTEN      -

通过端口号获取相关信息

$ netstat -an | grep ':80'

获取网络接口信息

$ 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
ens33      1500 0       618      0      0 0           805      0      0      0 BMRU
lo        65536 0       160      0      0 0           160      0      0      0 LRU

获取网络接口扩展信息

$ netstat -ei
Kernel Interface table
ens33     Link encap:Ethernet  HWaddr 00:0c:29:cc:27:dd  
          inet addr:192.168.240.134  Bcast:192.168.240.255  Mask:255.255.255.0
          inet6 addr: fe80::20c:29ff:fecc:27dd/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:634 errors:0 dropped:0 overruns:0 frame:0
          TX packets:817 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:48993 (48.9 KB)  TX bytes:475217 (475.2 KB)

lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:160 errors:0 dropped:0 overruns:0 frame:0
          TX packets:160 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1 
          RX bytes:11840 (11.8 KB)  TX bytes:11840 (11.8 KB)
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值