Linux基础
1 前言
一个问题,一篇文章,一出故事。
今天老板提出一个需求,需要证明某个服务的端口联通性正常,于是整理此文。
2 最佳实践
2.1 普通TCP端口测试
2.1.1 Telnet命令测试
telnet www.cmdschool.org 80
telnet是TCP端口测试的首先命令,一般的TCP端口均可适用,运行命令后,可见如下显示,
Trying 10.168.0.152... Connected to www.cmdschool.org. Escape character is '^]'.
以上是http端口,同样的https也适用,
telnet www.cmdschool.org 443
可见如下显示,
Trying 10.168.0.152... Connected to www.cmdschool.org. Escape character is '^]'.
2.1.2 curl命令测试
curl www.cmdschool.org 80
以上命令对于http可能以下命令更加合适,可见如下显示,
<html> <head><title>Index of /</title></head> <body> # ...
注:“# …”表示省略,以上返回html编码
同样的https也适用,
curl www.cmdschool.org 443
可见如下显示,
<html> <head><title>Index of /</title></head> <body> # ...
2.1.3 wget命令测试
wget --output-document=/dev/nul www.cmdschool.org:80
以上命令使用wget直接下载页面的方式测试联通性,可见如下显示,
HTTP request sent, awaiting response... 200 OK Length: unspecified [text/html] Saving to: ‘/dev/nul’ [ ] 3,600 --.-K/s in 0s 2021-06-29 16:55:18 (157 MB/s) - ‘/dev/nul’ saved [3600]
2.2 测试加密TCP端口
ssh -v -p 22 hd04.cmdschool.org
可见如下显示,
OpenSSH_6.6.1, OpenSSL 1.0.1e-fips 11 Feb 2013 debug1: Reading configuration data /etc/ssh/ssh_config debug1: /etc/ssh/ssh_config line 56: Applying options for * debug1: Connecting to hd04.cmdschool.org [10.168.0.28] port 22. debug1: Connection established. # ... Last login: Tue Jun 29 15:47:16 2021 from client.cmdschool.org
以上“# …”表示省略,以上包含“Connection established”即可证明链接已经建立,个人觉得ssh命令适合测试与ssh使用同样加密协议的端口,以下范例可以证明,
ssh -v -p 3269 ad01.cmdschool.org
可见如下显示,
OpenSSH_6.6.1, OpenSSL 1.0.1e-fips 11 Feb 2013 debug1: Reading configuration data /etc/ssh/ssh_config debug1: /etc/ssh/ssh_config line 56: Applying options for * debug1: Connecting to ad01.cmdschool.org [10.168.0.42] port 3269. debug1: Connection established. # ... ssh_exchange_identification: read: Connection reset by peer
没有评论