返回介绍

Hack-95 Netstat 命令

发布于 2025-03-08 17:41:49 字数 5154 浏览 0 评论 0 收藏 0

Netstat 命令

netstat 命令显示网络连接的状态。

显示当前活动的网络连接

➤ netstat -an
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address           Foreign Address         State      
tcp        0      0 127.0.0.1:44244         0.0.0.0:*               LISTEN     
tcp        0      0 127.0.1.1:53            0.0.0.0:*               LISTEN     
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN     
tcp        0      0 127.0.0.1:3306          0.0.0.0:*               LISTEN     
... ... ...
Active UNIX domain sockets (servers and established)
Proto RefCnt Flags       Type       State         I-Node   Path
unix  2      [ ]         DGRAM                    22370    /run/user/1000/systemd/notify
unix  2      [ ACC ]     STREAM     LISTENING     23426    @/tmp/.ICE-unix/2548
unix  2      [ ACC ]     STREAM     LISTENING     22371    /run/user/1000/systemd/private
unix  2      [ ACC ]     SEQPACKET  LISTENING     8934     /run/udev/control
unix  2      [ ACC ]     STREAM     LISTENING     20436    /run/user/1000/keyring/control
unix  2      [ ACC ]     STREAM     LISTENING     24609    /tmp/fcitx-socket-:0
unix  2      [ ACC ]     STREAM     LISTENING     27013    /tmp/sogou-qimpanel-cell

显示运行程序的进程号/程序名

➤ netstat -tapn
(Not all processes could be identified, non-owned process info
 will not be shown, you would have to be root to see it all.)
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 127.0.0.1:44244         0.0.0.0:*               LISTEN      9720/1452662683780-
tcp        0      0 127.0.1.1:53            0.0.0.0:*               LISTEN      -               
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      -               
tcp        0      0 127.0.0.1:3306          0.0.0.0:*               LISTEN      -               
tcp        0      0 127.0.0.1:587           0.0.0.0:*               LISTEN      -               
tcp        0      0 127.0.0.1:47034         127.0.0.1:44244         ESTABLISHED 9680/editor     
tcp        0      0 127.0.0.1:44244         127.0.0.1:47034         ESTABLISHED 9720/1452662683780-
tcp        0      0 127.0.0.1:47038         127.0.0.1:44244         ESTABLISHED 9680/editor     
tcp        0      0 127.0.0.1:44244         127.0.0.1:47038         ESTABLISHED 9720/1452662683780-
tcp6       0      0 :::1080                 :::*                    LISTEN      31588/shadowsocks
tcp6       0      0 :::1088                 :::*                    LISTEN      31589/shadowsocks

在最后一列有运行的进程号/程序名。

显示路由表

➤ netstat --route
Kernel IP routing table
Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface
link-local      *               255.255.0.0     U         0 0          0 docker0
172.17.0.0      *               255.255.0.0     U         0 0          0 docker0

显示 RAW 网络统计

➤ netstat --statistics --raw
Ip:
    3046724 total packets received
    20 forwarded
    0 incoming packets discarded
    3045898 incoming packets delivered
    1985453 requests sent out
    48 outgoing packets dropped
    1611 dropped because of missing route
Icmp:
    474 ICMP messages received
    0 input ICMP message failed.
    ICMP input histogram:
        destination unreachable: 471
        echo requests: 3
    1999 ICMP messages sent
    0 ICMP messages failed
    ICMP output histogram:
        destination unreachable: 1996
        echo replies: 3
IcmpMsg:
        InType3: 471
        InType8: 3
        OutType0: 3
        OutType3: 1996
UdpLite:
IpExt:
    InNoRoutes: 38
    InMcastPkts: 143
    OutMcastPkts: 164
    InBcastPkts: 310
    OutBcastPkts: 6
    InOctets: 5251249872
    OutOctets: 149575262
    InMcastOctets: 26980
    OutMcastOctets: 27820
    InBcastOctets: 32799
    OutBcastOctets: 284
    InNoECTPkts: 3750022
➤

(显示太占篇幅了...)

其他

  • netstat –-tcp –-numeric 列出本机的 TCP 连接
  • netstat --tcp --listening –-programs 显示系统正在监听的端口以及程序
➤ netstat --tcp --listening –-programs -n
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State      
tcp        0      0 127.0.0.1:44244         0.0.0.0:*               LISTEN     
tcp        0      0 127.0.1.1:53            0.0.0.0:*               LISTEN     
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN     
tcp        0      0 127.0.0.1:3306          0.0.0.0:*               LISTEN     
tcp        0      0 127.0.0.1:587           0.0.0.0:*               LISTEN     
tcp6       0      0 :::1080                 :::*                    LISTEN     
tcp6       0      0 :::1088                 :::*                    LISTEN
  • netstat –rnC 显示路由缓存

本书简介:

  • Linux 进阶技巧
  • 巧妙的命令组合
  • Bash 某些技巧
  • 一共一百零一个(包括充数的)
  • 最后有个奖励章(额外技巧)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文