服务器上运行了一个服务,想测试一下端口通不通,可以通过以下一些方法来测试。

telnet

常见的tcp端口测试都是用的telnet,用法也很简单

1
telnet 10.0.0.7 22

成功会显示:

1
2
3
4
Trying 10.0.0.7...
Connected to 10.0.0.7.
Escape character is '^]'.
SSH-2.0-OpenSSH_7.4

失败会显示:

1
2
Trying 10.0.0.7...
telnet: Unable to connect to remote host: Connection refused

ssh

使用

1
ssh root@localhost -p 8000

失败会显示

1
ssh: connect to host localhost port 8001: Connection refused

curl

curl ip:port

失败会显示

1
curl: (7) Failed to connect to localhost port 8001: Connection refused

netcat

检查TCP端口

下面的命令会检查远程主机上是否打开了端口 80、22 和 9000:

1
nc -zv 192.168.2.1 80 22 9000

也可以指定端口扫描的范围(速度非常快):

1
nc -zv 192.168.2.1 20-9000

检查UDP端口

1
nc -vuz 10.16.83.10 161

通的话, 会显示:

不通的话, 会显示:
image.png