Linux服务器上测试TCP/UDP端口的连通性
Posted xiangjai
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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工具已经安装
# yum install nc
# yum install telnet
测试tcp端口的连通性:
语法如下:
telnet <hostname/IP address> <port number>
如下是连通成功的例子:
[root@centos7-kh62 ~]# telnet 10.100.1.29 22
Trying 10.100.1.29...
Connected to 10.100.1.29.
Escape character is '^]'.
SSH-2.0-OpenSSH_8.1
Invalid SSH identification string.
Connection closed by foreign host.
如下是连通不成功的例子:
[root@centos7-kh62 ~]# telnet 10.100.1.29 23
Trying 10.100.1.29...
telnet: connect to address 10.100.1.29: Connection refused
使用nc命令来测试udp端口的连通性:
语法:
nc -z -v -u <hostname/IP address> <port number>
如下是连接成功的例子
[root@centos7-kh62 ~]# nc -z -v -u 10.100.1.29 1540
Ncat: Version 7.50 ( https://nmap.org/ncat )
Ncat: Connected to 10.100.1.29:1540.
Ncat: UDP packet sent successfully
Ncat: 1 bytes sent, 0 bytes received in 2.02 seconds.
如下是连接不成功的例子
[root@centos7-kh62 ~]# nc -z -v -u 10.100.1.29 111
Ncat: Version 7.50 ( https://nmap.org/ncat )
Ncat: Connected to 10.100.1.29:111.
Ncat: Connection refused.
使用nc命令来测试tcp端口的连通性:
语法:
nc -z -v <hostname/IP address> <port number>
如下是连接成功的例子
[root@centos7-kh62 ~]# nc -z -v 10.100.1.29 22
Ncat: Version 7.50 ( https://nmap.org/ncat )
Ncat: Connected to 10.100.1.29:22.
Ncat: 0 bytes sent, 0 bytes received in 0.01 seconds.
参考: https://blog.csdn.net/msdnchina/article/details/54783382#
以上是关于Linux服务器上测试TCP/UDP端口的连通性的主要内容,如果未能解决你的问题,请参考以下文章