1. 首页
  2. 技术
  3. Linux

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

  1. Trying 192.118.20.95…
  2. Connected to 192.118.20.95.
  3. Escape character is ‘^]’.
  4. SSH-2.0-OpenSSH_6.6.1
  5. Protocol mismatch.
  6. Connection closed by foreign host.
  7. 如下是连通不成功的例子:
  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/IP address> <port number>
如下是连通成功的例子:
  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/IP address> <port number>
  1. # nc -z -v -u 192.118.20.95 123
  2. Connection to 192.118.20.95 123 port [udp/ntp] succeeded!

 

原创文章,作者:admin,如若转载,请注明出处:https://www.huiyingwu.com/3070/

发表评论

电子邮件地址不会被公开。 必填项已用*标注