歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> 關於Linux >> Linux之netstat命令

Linux之netstat命令

日期:2017/3/1 16:21:37   编辑:關於Linux
Linux之netstat命令 簡介 Netstat 命令用於顯示各種網絡相關信息,如網絡連接,路由表,接口狀態 (Interface Statistics),masquerade 連接,多播成員 (Multicast Memberships) 等等。 輸出信息含義 執行netstat後,其輸出結果為 [plain] [root@localhost ~]# netstat Active Internet connections (w/o servers) Proto Recv-Q Send-Q Local Address Foreign Address State getnameinfo failed getnameinfo failed tcp 0 132 [UNKNOWN]:ssh [UNKNOWN]:3101 ESTABLISHED Active UNIX domain sockets (w/o servers) Proto RefCnt Flags Type State I-Node Path unix 9 [ ] DGRAM 7700 /dev/log unix 2 [ ] DGRAM 8754 @/var/run/hal/hotplug_socket unix 2 [ ] DGRAM 5079 @udevd unix 2 [ ] DGRAM 43227 unix 3 [ ] STREAM CONNECTED 12811 /var/run/dbus/system_bus_socket unix 3 [ ] STREAM CONNECTED 12810 unix 3 [ ] STREAM CONNECTED 8749 /var/run/dbus/system_bus_socket unix 3 [ ] STREAM CONNECTED 8748 unix 3 [ ] STREAM CONNECTED 8742 /var/run/dbus/system_bus_socket unix 3 [ ] STREAM CONNECTED 8741 unix 3 [ ] STREAM CONNECTED 8618 unix 3 [ ] STREAM CONNECTED 8617 unix 2 [ ] DGRAM 8494 unix 2 [ ] DGRAM 8429 unix 2 [ ] DGRAM 8414 unix 2 [ ] DGRAM 8387 unix 2 [ ] DGRAM 8268 unix 3 [ ] STREAM CONNECTED 7890 unix 3 [ ] STREAM CONNECTED 7889 unix 2 [ ] DGRAM 7780 unix 2 [ ] DGRAM 7708 從整體上看,netstat的輸出結果可以分為兩個部分: 一個是Active Internet connections,稱為有源TCP連接,其中"Recv-Q"和"Send-Q"指%0A的是接收隊列和發送隊列。這些數字一般都應該是0。如果不是則表示軟件包正在隊列中堆積。這種情況只能在非常少的情況見到。 另一個是Active UNIX domain sockets,稱為有源Unix域套接口(和網絡套接字一樣,但是只能用於本機通信,性能可以提高一倍)。 Proto顯示連接使用的協議,RefCnt表示連接到本套接口上的進程號,Types顯示套接口的類型,State顯示套接口當前的狀態,Path表示連接到套接口的其它進程使用的路徑名。 常見參數 -a (all)顯示所有選項,默認不顯示LISTEN相關 -t (tcp)僅顯示tcp相關選項 -u (udp)僅顯示udp相關選項 -n 拒絕顯示別名,能顯示數字的全部轉化成數字。 -l 僅列出有在 Listen (監聽) 的服務狀態 -p 顯示建立相關鏈接的程序名 -r 顯示路由信息,路由表 -e 顯示擴展信息,例如uid等 -s 按各個協議進行統計 -c 每隔一個固定時間,執行該netstat命令。 提示:LISTEN和LISTENING的狀態只有用-a或者-l才能看到 實用命令實例 1. 列出所有端口 (包括監聽和未監聽的) 列出所有端口 netstat -a [plain] # 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 [plain] # 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 [plain] <span style="font-size:12px;"># 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 *:* </span> 2. 列出所有處於監聽狀態的 Sockets 只顯示監聽端口 netstat -l [plain] # 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 [plain] # 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 [plain] # 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 *:* 3. 查看端口被哪個進程占用 列出端口進程占用情況 netstat -pan |grep 8019 [plain] <span style="font-size:12px;">[root@localhost ~]# netstat -pan |grep 8019 unix 2 [ ACC ] STREAM LISTENING 8019 4765/acpid /var/run/acpid.socket</span>
Copyright © Linux教程網 All Rights Reserved