怎么在Linux服务器上测试TCP/UDP端口的连通性?

2018/10 29 14:10

怎么在Linux服务器上测试TCP/UDP端口的连通性?

翻译自:
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工具已经安装

  1. # yum install nc
  2. # yum install telnet

测试tcp端口的连通性:
语法如下:

telnet <hostname/IPaddress><portnumber>

如下是连通成功的例子:

  1. # telnet 192.118.20.95 22
  2. Trying 192.118.20.95...
  3. Connected to 192.118.20.95.
  4. Escape character is '^]'.
  5. SSH-2.0-OpenSSH_6.6.1
  6. Protocol mismatch.
  7. Connection closed by foreign host.

如下是连通不成功的例子:

  1. # telnet 192.118.20.95 22
  2. Trying 192.118.20.95...
  3. telnet: connect to address 192.118.20.95: No route to host

使用nc命令来测试tcp端口的连通性:
语法:

nc -z -v <hostname/IPaddress><portnumber>

如下是连通成功的例子:

  1. # nc -z -v 192.118.20.95 22
  2. Connection to 192.118.20.95 22 port [tcp/ssh] succeeded!

如下是连通不成功的例子:

  1. # nc -z -v 192.118.20.95 22
  2. nc: connect to 192.118.20.95 port 22 (tcp) failed: No route to host

使用nc命令来测试udp端口的连通性:
语法:

nc -z -v -u <hostname/IPaddress><portnumber>

 

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

--转载请注明: http://91o.cc/%e6%80%8e%e4%b9%88%e5%9c%a8linux%e6%9c%8d%e5%8a%a1%e5%99%a8%e4%b8%8a%e6%b5%8b%e8%af%95tcp-udp%e7%ab%af%e5%8f%a3%e7%9a%84%e8%bf%9e%e9%80%9a%e6%80%a7%ef%bc%9f/

作者 - 分类 未分类

发表回复

(必填)