Linux 网络工具之 netstat 详解

文章
林里克斯

Linux 网络工具之 netstat 详解


实验平台:CentOS Linux release 7.6.1810 (Core)

net-tools Version:net-tools 2.10-alpha



一、netstat 详解


1.安装命令

$ sudo yum -y install net-tools

2.参数详解

$ netstat --help

    -r, --route              #显示路由表,同等于 route -n
    -I, --interfaces=<Iface> #显示网络接口表信息,可用 -I=eth0 指定显示 eth 网卡的信息
    -i, --interfaces         #显示网络接口表信息
    -g, --groups             #显示多重广播功能群组组员名单
    -s, --statistics         #显示网络统计信息(如SNMP)
    -M, --masquerade         #显示伪装的网络连线

    -v, --verbose            #显示详细信息
    -W, --wide               #显示RAW传输协议的连线状况
    -n, --numeric            #直接使用 IP 地址,而不通过域名服务器
    --numeric-hosts          #不过过 /etc/hosts 表
    --numeric-ports          don't resolve port names
    --numeric-users          don't resolve user names
    -N, --symbolic           #显示网络硬件外围设备的符号连接名称
    -e, --extend             #显示网络其他相关信息
    -p, --programs           #显示正在使用此网络的 PID 及应用名称
    -o, --timers             #显示计时器
    -c, --continuous         #持续显示监听信息,默认为 1 秒显示异常,可跟数字来表示几秒显示一次

    -l, --listening          #显示监听服务 socket
    -a, --all                #显示所有服务的 socket (默认是显示: 已连接的)
    -F, --fib                #显示转发 FIB 信息 (default)
    -C, --cache              #显示路由缓存而不是 FIB 信息
    -Z, --context            #显示 Socket 的 SELinux 安全上下文

    <Socket>
    -t, --tcp                #只显示 tcp 监听
    -u, --udp                #只显示 udp 监听

二、使用案例


1.查看 TCP 连接数和状态

$ netstat -n | awk '/^tcp/ {++S[$NF]} END {for(a in S) print a, S[a]}'
ESTABLISHED 72
TIME_WAIT 9

具体信息可参考此篇文章 -> Linux 下查看 TCP 的连接数和状态

2.查看监听的 tcp 地址及端口

$ netstat -tlnp
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:22              0.0.0.0:*               LISTEN      6488/sshd           
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      6730/master         
tcp6       0      0 :::22                   :::*                    LISTEN      6488/sshd           
tcp6       0      0 ::1:25                  :::*                    LISTEN      6730/master

3.查看某进程在使用特定端口的进程 ID

$ netstat -pantu | grep 10:3306
tcp6       0      0 10.10.10.10:3306                 :::*                    LISTEN      9518/java

4.显示网络统计信息

$ netstat -s
Ip:
    305674 total packets received
    0 forwarded
    0 incoming packets discarded
    305671 incoming packets delivered
    22851 requests sent out
Icmp:
    1 ICMP messages received
    0 input ICMP message failed.
    ICMP input histogram:
        destination unreachable: 1
    4 ICMP messages sent
    0 ICMP messages failed
    ICMP output histogram:
        destination unreachable: 4
IcmpMsg:
        InType3: 1
        OutType3: 4
Tcp:
    58 active connections openings
    1 passive connection openings
    0 failed connection attempts
    0 connection resets received
    1 connections established
    29143 segments received
    25042 segments send out
    1 segments retransmited
    0 bad segments received.
    0 resets sent
Udp:
    66 packets received
    4 packets to unknown port received.
    0 packet receive errors
    71 packets sent
    0 receive buffer errors
    0 send buffer errors
UdpLite:
TcpExt:
    54 TCP sockets finished time wait in fast timer
    78 delayed acks sent
    1 delayed acks further delayed because of locked socket
    Quick ack mode was activated 6 times
    5014 packets directly queued to recvmsg prequeue.
    167900 bytes directly in process context from backlog
    9225220 bytes directly received in process context from prequeue
    17991 packet headers predicted
    4790 packets header predicted and directly queued to user
    1397 acknowledgments not containing data payload received
    3235 predicted acknowledgments
    1 congestion windows recovered without slow start after partial ack
    1 other TCP timeouts
    6 DSACKs sent for old packets
    TCPSackShiftFallback: 2
    TCPRcvCoalesce: 1599
    TCPAutoCorking: 219
    TCPSynRetrans: 1
    TCPOrigDataSent: 7673
    TCPHystartTrainDetect: 1
    TCPHystartTrainCwnd: 18
IpExt:
    InNoRoutes: 3
    InBcastPkts: 276457
    InOctets: 124820243
    OutOctets: 5979059
    InBcastOctets: 80315333
    InNoECTPkts: 322378

Over~

版权协议须知!

本篇文章来源于 Uambiguous ,如本文章侵犯到任何版权问题,请立即告知本站,本站将及时予与删除并致以最深的歉意

748 0 2020-12-27


分享:
icon_mrgreen.gificon_neutral.gificon_twisted.gificon_arrow.gificon_eek.gificon_smile.gificon_confused.gificon_cool.gificon_evil.gificon_biggrin.gificon_idea.gificon_redface.gificon_razz.gificon_rolleyes.gificon_wink.gificon_cry.gificon_surprised.gificon_lol.gificon_mad.gificon_sad.gificon_exclaim.gificon_question.gif
博主卡片
林里克斯 博主大人
一个致力于Linux的运维平台
运维时间
搭建这个平台,只为分享及记载自己所遇之事和难题。

现在时间 2024-05-18

今日天气
站点统计
  • 文章总数:240篇
  • 分类总数:29个
  • 评论总数:10条
  • 本站总访问量 222832 次

@奥奥

@Wong arrhenius 牛比

@MakerFace 厉害了!