在 Linux/Ubuntu 系統中,可以透過 vim /etc/services 查看,「port」 與 「服務」的對應關係。
Netstat 與 Nmap 最大的差別就是,Netstat 查詢本地主機上處於傾聽(listen)狀態的連接埠,而 Nmap 可以查詢外部特定主機所開啟的網路連接埠。
Netstat:
$> sudo netstat -ntulp | grep LISTEN #查詢本地主機所有開啟的 TCP 與 UDP 連接埠
-n | 顯示 IP 位址,不進行 DNS 查詢 |
-t | 列出 TCP 傳輸協定的連線 |
-u | 列出 UDP 傳輸協定的連線 |
-l | 列出傾聽(listen)狀態的埠口 |
-p | 列出使用連接埠的應用程式與 PID |
輸出結果:
在這個輸出中會包含傳輸協定(例如 tcp
)、傾聽位址與埠號(例如 0.0.0.0:22
),以及使用連接埠的應用程式與 PID(例如 1683/sshd
)。
Nmap:
$> sudo nmap -sT -sU localhost # 掃描 localhost 所有開啟的 TCP 與 UDP 連接埠 $> sudo nmap -sT -sU 192.168.1.2 # 掃描 192.168.1.2 所有開啟的 TCP 與 UDP 連接埠
-sT | 掃瞄 TCP 封包已建立的連線 connect() |
-sU | 以 UDP 的封包格式進行掃瞄 |
-sP | 以 ping 的方式進行掃瞄 |