如何在 Linux 上即時檢視 TCP 和 UDP 埠?
在計算機網路中,網路服務在組成網路的每臺計算機中執行一個軟體。在 Linux 系統中,這個網路軟體使用 TCP 或 UDP 等協議以及埠號。TCP 被稱為傳輸控制協議,UDP 被稱為使用者資料報協議。在本文中,我們將看到如何以即時方式監控執行在這些協議上的埠即套接字。
開啟埠列表
第一步,我們需要檢視系統中可用的開放埠。開放埠即已準備好偵聽埠並接受來自其他系統的請求。下面是用來列出開放埠的命令。
$ sudo netstat –tulpn The meaning of various flags is as below. t - enable listing of TCP ports. u - enables listing of UDP ports. l - print only the open sockets. p - print the program name n – print the port number
執行以上程式碼,我們得到以下結果 −
Active Internet connections (only Proto Recv-Q Send-Q Local Address Foreign Address State PM/Program name tcp 127.0.1.1:53 0.0.0.0:* LISTEN 966/dnsmasq tcp 0.0.0.0:22 0.0.0.0:* LISTEN 941/sshd tcp 127.0.0.1:631 0.0.0.0:* LISTEN 11450/cupsd tcp6 :::22 LISTEN 941/sshd tcp6 ::1:631 LISTEN 11450/cupsd udp 0.0.0.0:50228 0.0.0.0:* 792/avahi-daemon: r udp 0.0.0.0:5353 0.0.0.0:* 792/avahi-daemon: r udp 127.0.1.1:53 0.0.0.0:* 966/dnsmasq udp 0.0.0.0:68 0.0.0.0:* 949/dhclient udp 0.0.0.0:51324 0.0.0.0:* 966/dnsmasq udp 0.0.0.0:631 0.0.0.0:* 11452/cups-browsed udp6 :::5353 792/avahi-daemon: r ud.6 :::50929 792 avahi-daemon: r
即時開啟的埠
但如果你想即時檢視這些埠,以便監控已傳送和接收資料的位元組數,那麼我們必須新增 watch 標誌。
$ sudo watch netstat –tulpn
執行以上程式碼,我們得到以下結果 −
Active Internet connections (only servers) Proto Recv-Q Send-QLocal Address Foreign Address State PID/Program name tcp 127.0.1.1:53 0.0.0.0:* LISTEN 966/dnsmasq tcp 0.0.0.0:22 0.0.0.0:* LISTEN 941/sshd tcp 127.0.0.1:631 0.0.0.0:* LISTEN 11450/cupsd tcp6 63 :::22 ••LISTEN 941/sshd tcp6 ::1:631 LISTEN 11450/cupsd udp 0.0.0.0:50228 0.0.0.0:* 792/avahi-daemon: r udp 0.0.0.0:5353 0.0.0.0:* 792/avahi-daemon: r udp 127.0.1.1:53 0.0.0.0:* 966/dnsmasq udp 0.0.0.0:68 0.0.0.0:* 949/dhclient udp 0.0.0.0:51324 0.0.0.0:* 966/dnsmasq udp 0.0.0.0:631 0.0.0.0:* 11452/cups-browsed udp6 :::5353 • • • 792/avahi-daemon: r udp6 :::50929 792/avahi-daenon: r
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP