温馨提示×

怎样测试openssl连通性

小樊
40
2026-07-01 15:44:58
栏目: 云计算

测试 OpenSSL 连通性通常分几种场景,下面按最常用方式给你整理(从简单到完整)。


一、最常用:测试 TLS/SSL 端口是否可达(代替 telnet)

openssl s_client -connect example.com:443

说明

  • 会尝试建立 TLS 连接
  • 成功时你会看到证书信息、握手成功提示
  • 失败会卡住或直接报错

Ctrl+C 退出


二、只看是否连通(不进交互)

echo | openssl s_client -connect example.com:443

或更简洁:

openssl s_client -connect example.com:443 </dev/null

三、只验证连通性(不关心证书,常用于排查)

openssl s_client -connect example.com:443 -verify 0

四、指定 TLS 版本(排查版本不兼容)

# TLS 1.2
openssl s_client -connect example.com:443 -tls1_2

# TLS 1.3
openssl s_client -connect example.com:443 -tls1_3

五、测试 SNI(虚拟主机必备)

openssl s_client -connect example.com:443 -servername example.com

⚠️ 非常重要
很多 CDN / 云 / Nginx 虚拟主机 不指定 SNI 会失败


六、查看证书信息(排查证书问题)

openssl s_client -connect example.com:443 \
| openssl x509 -noout -text

或只看有效期:

openssl s_client -connect example.com:443 \
| openssl x509 -noout -dates

七、测试 SMTP / IMAP / POP3(STARTTLS)

# SMTP
openssl s_client -starttls smtp -connect mail.example.com:25

# IMAP
openssl s_client -starttls imap -connect mail.example.com:143

# POP3
openssl s_client -starttls pop3 -connect mail.example.com:110

八、测试双向 TLS(客户端证书)

openssl s_client \
  -connect example.com:443 \
  -cert client.crt \
  -key client.key \
  -CAfile ca.crt

九、常见错误速查

错误 含义
connect: Connection refused 端口没开
no peer certificate available SNI 或端口不对
alert handshake failure TLS 版本或加密套件不匹配
certificate verify failed CA 不受信任

十、快速判断“能不能通”

最实用的一条:

echo | openssl s_client -connect example.com:443 -servername example.com 2>/dev/null | head -20

如果你愿意,可以告诉我:

  • ✅ 是 HTTPS / 数据库 / MQ / 内部服务
  • ✅ 报错信息
  • ✅ Linux / Windows / Docker 环境

我可以给你更精确的测试命令

0