zoukankan      html  css  js  c++  java
  • Linux的netstat

    1. 列出所有端口 (包括监听和未监听的)

      列出所有端口 netstat -a

    复制代码
    # netstat -a | more
    Active Internet connections (servers and established)
    Proto Recv-Q Send-Q Local Address Foreign Address State
    tcp 0 0 localhost:30037 *:* LISTEN
    udp 0 0 *:bootpc *:*

    Active UNIX domain sockets (servers and established)
    Proto RefCnt Flags Type State I-Node Path
    unix 2 [ ACC ] STREAM LISTENING 6135 /tmp/.X11-unix/X0
    unix 2 [ ACC ] STREAM LISTENING 5140 /var/run/acpid.socket
    复制代码

      列出所有 tcp 端口 netstat -at

    复制代码
    # netstat -at
    Active Internet connections (servers and established)
    Proto Recv-Q Send-Q Local Address Foreign Address State
    tcp 0 0 localhost:30037 *:* LISTEN
    tcp 0 0 localhost:ipp *:* LISTEN
    tcp 0 0 *:smtp *:* LISTEN
    tcp6 0 0 localhost:ipp [::]:* LISTEN
    复制代码

      列出所有 udp 端口 netstat -au

    # netstat -au
    Active Internet connections (servers and established)
    Proto Recv-Q Send-Q Local Address Foreign Address State
    udp 0 0 *:bootpc *:*
    udp 0 0 *:49119 *:*
    udp 0 0 *:mdns *:*

     

    2. 列出所有处于监听状态的 Sockets

      只显示监听端口 netstat -l

    # netstat -l
    Active Internet connections (only servers)
    Proto Recv-Q Send-Q Local Address Foreign Address State
    tcp 0 0 localhost:ipp *:* LISTEN
    tcp6 0 0 localhost:ipp [::]:* LISTEN
    udp 0 0 *:49119 *:*

      只列出所有监听 tcp 端口 netstat -lt

    # netstat -lt
    Active Internet connections (only servers)
    Proto Recv-Q Send-Q Local Address Foreign Address State
    tcp 0 0 localhost:30037 *:* LISTEN
    tcp 0 0 *:smtp *:* LISTEN
    tcp6 0 0 localhost:ipp [::]:* LISTEN

      只列出所有监听 udp 端口 netstat -lu

    # netstat -lu
    Active Internet connections (only servers)
    Proto Recv-Q Send-Q Local Address Foreign Address State
    udp 0 0 *:49119 *:*
    udp 0 0 *:mdns *:*

      只列出所有监听 UNIX 端口 netstat -lx

    复制代码
    # netstat -lx
    Active UNIX domain sockets (only servers)
    Proto RefCnt Flags Type State I-Node Path
    unix 2 [ ACC ] STREAM LISTENING 6294 private/maildrop
    unix 2 [ ACC ] STREAM LISTENING 6203 public/cleanup
    unix 2 [ ACC ] STREAM LISTENING 6302 private/ifmail
    unix 2 [ ACC ] STREAM LISTENING 6306 private/bsmtp
    复制代码

     

    3. 在 netstat 输出中显示 PID 和进程名称 netstat -p

    netstat -p 可以与其它开关一起使用,就可以添加 “PID/进程名称” 到 netstat 输出中,这样 debugging 的时候可以很方便的发现特定端口运行的程序。

    # netstat -pt
    Active Internet connections (w/o servers)
    Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
    tcp 1 0 ramesh-laptop.loc:47212 192.168.185.75:www CLOSE_WAIT 2109/firefox

    tcp 0 0 ramesh-laptop.loc:52750 lax:www ESTABLISHED 2109/firefox 

    4. 找出程序运行的端口

    并不是所有的进程都能找到,没有权限的会不显示,使用 root 权限查看所有的信息。

    # netstat -ap | grep ssh
    tcp 1 0 dev-db:ssh 101.174.100.22:39213 CLOSE_WAIT -
    tcp 1 0 dev-db:ssh 101.174.100.22:57643 CLOSE_WAIT -

      找出运行在指定端口的进程

    # netstat -an | grep ':80' 

    http://www.thegeekstuff.com/2010/03/netstat-command-examples/ 
  • 相关阅读:
    OSError: cannot open resource(pillow错误处理)
    boost 库中文教程
    博客案例
    requests模块
    浅析Python中的struct模块
    面试基础知识点总结
    ant安装、环境变量配置及验证
    TestNG学习-001-基础理论知识
    selenium 常见面试题以及答案
    HTML5
  • 原文地址:https://www.cnblogs.com/itech/p/2678041.html
Copyright © 2011-2022 走看看