編碼的世界 / 優質文選 / 生物

怎麼在Linux服務器上測試TCP/UDP端口的連通性?


2022年7月19日
-   

翻譯自: How to Test Port[TCP/UDP] Connectivity from a Linux Server (文檔 ID 2212626.1) 適用於: Linux OS - Version Oracle Linux 5.0 to Oracle Linux 6.8 [Release OL5 to OL6U8] Information in this document applies to any platform. 目標: 在Linux服務器上檢查TCP/UDP端口的連通性。 解決方案: telnet和nc 是用來測試端口連通性的一般工具。 telnet可以測試tcp端口的連通性。 nc可以測試tcp和udp端口的連通性。 請確保telnet和nc工具已經安裝
# yum install nc
# yum install telnet

測試tcp端口的連通性: 語法如下:
telnet <hostname/IP address> <port number>

如下是連通成功的例子:
# telnet 192.118.20.95 22
Trying 192.118.20.95
Connected to 192.118.20.95.
Escape character is '^]'.
SSH-2.0-OpenSSH_6.6.1
Protocol mismatch.
Connection closed by foreign host.

如下是連通不成功的例子:
# telnet 192.118.20.95 22
Trying 192.118.20.95
telnet: connect to address 192.118.20.95: No route to host

使用nc命令來測試tcp端口的連通性: 語法:
nc -z -v <hostname/IP address> <port number>

如下是連通成功的例子:
# nc -z -v 192.118.20.95 22
Connection to 192.118.20.95 22 port [tcp/ssh] succeeded!

如下是連通不成功的例子:
# nc -z -v 192.118.20.95 22
nc: connect to 192.118.20.95 port 22 (tcp) failed: No route to host

使用nc命令來測試udp端口的連通性: 語法:
nc -z -v -u <hostname/IP address> <port number>

 
# nc -z -v -u 192.118.20.95 123
Connection to 192.118.20.95 123 port [udp/ntp] succeeded!

 

熱門文章