这篇文章介绍了如何使用telnet和nc命令来测试端口是否开放。首先,使用telnet ip port命令来判断端口是否通,如果连接被拒绝则端口不通。然后,文章介绍了nc命令的使用,通过nc -v localhost port命令来检测端口,如果显示Connection refused则端口不通,如果显示Connection to x.x.x.x port [tcp/http] succeeded!则端口通。
一般情况下使用telnet ip port
判断端口通不通,其实测试方法不止这一种,本文主要介绍nc
检测工具。
1、使用telnet判断
1)先用telnet连接不存在的端口
[root@localhost ~]# telnet 10.0.250.3 80
Trying 10.0.250.3...
telnet: connect to address 10.0.250.3: Connection refused #直接提示连接被拒绝
2)再连接存在的端口
[root@localhost ~]# telnet localhost 22
Trying ::1...
Connected to localhost. #看到Connected就连接成功了
Escape character is '^]'.
SSH-2.0-OpenSSH_5.3
a
Protocol mismatch.
Connection closed by foreign host.
2、nc命令
1)不存在的端口
[root@localhost] nc -v localhost 8889
Ncat: Version 7.50 ( https://nmap.org/ncat )
Ncat: Connection refused.
2)存在的端口
[root@localhost] nc -v localhost 8889
Connection to x.x.x.x 8889 port [tcp/http] succeeded!