netstat命令簡析

來源:互聯網
上載者:User

netstat命令簡析 netstat 命令可以協助檢查原生網路狀況,man netstat 可以看到對其的基本描述:netstat - Print network connections, routing tables, interface statistics, masquerade connections, and multicast memberships 先來一個簡單的例子,要顯示tcp協議,使用-t參數,包括了tcp和tcp6[plain]  netstat -t  Active Internet connections (w/o servers)  Proto Recv-Q Send-Q Local Address           Foreign Address         State        tcp        0      0 localhost:59226         localhost:8527          ESTABLISHED  tcp        0      0 bogon:44385             117.79.93.222:http      TIME_WAIT    tcp        0      0 localhost:8527          localhost:59305         CLOSE_WAIT   tcp        0      0 localhost:8527          localhost:59235         ESTABLISHED  tcp        0      1 bogon:36113             tf-in-f19.1e100.n:https SYN_SENT     tcp        0      0 bogon:49941             117.79.93.196:http      TIME_WAIT    tcp        0      0 bogon:53574             117.79.93.208:http      ESTABLISHED  tcp        0      0 localhost:59259         localhost:8527          ESTABLISHED  數量太多,只顯示了一部分。 添加一個-l參數,會只顯示監聽本地連接埠的TCP程式,現在一下子程式少了很多。[plain] netstat -tl  Active Internet connections (only servers)  Proto Recv-Q Send-Q Local Address           Foreign Address         State        tcp        0      0 localhost:8527          *:*                     LISTEN       tcp        0      0 *:http                  *:*                     LISTEN       tcp        0      0 localhost:domain        *:*                     LISTEN       tcp        0      0 localhost:ipp           *:*                     LISTEN       tcp        0      0 *:https                 *:*                     LISTEN       tcp6       0      0 ip6-localhost:8527      [::]:*                  LISTEN       tcp6       0      0 ip6-localhost:ipp       [::]:*                  LISTEN    注意上面的Local Address一列,顯示的不是ip地址,而是localhost, 如果想要顯示IP地址,添加一個參數-n[plain] netstat -tln  Active Internet connections (only servers)  Proto Recv-Q Send-Q Local Address           Foreign Address         State        tcp        0      0 127.0.0.1:8527          0.0.0.0:*               LISTEN       tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN       tcp        0      0 127.0.0.1:53            0.0.0.0:*               LISTEN       tcp        0      0 127.0.0.1:631           0.0.0.0:*               LISTEN       tcp        0      0 0.0.0.0:443             0.0.0.0:*               LISTEN       tcp6       0      0 ::1:8527                :::*                    LISTEN       tcp6       0      0 ::1:631                 :::*                    LISTEN    如果還想顯示進程名稱和ID,再添加一個參數-p[plain] netstat -tlnp  Active Internet connections (only servers)  Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name  tcp        0      0 127.0.0.1:8527          0.0.0.0:*               LISTEN      6506/ssh          tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      889/nginx         tcp        0      0 127.0.0.1:53            0.0.0.0:*               LISTEN      1268/dnsmasq      tcp        0      0 127.0.0.1:631           0.0.0.0:*               LISTEN      590/cupsd         tcp        0      0 0.0.0.0:443             0.0.0.0:*               LISTEN      889/nginx         tcp6       0      0 ::1:8527                :::*                    LISTEN      6506/ssh          tcp6       0      0 ::1:631                 :::*                    LISTEN      590/cupsd    配合grep,就可以尋找監聽本地某連接埠的進程[plain] netstat -tlnp | grep 127.0.0.1:8527  tcp        0      0 127.0.0.1:8527          0.0.0.0:*               LISTEN      6506/ssh   

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.