测试 OpenSSL 连通性通常分几种场景,下面按最常用方式给你整理(从简单到完整)。
openssl s_client -connect example.com:443
✅ 说明
✅ 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 1.2
openssl s_client -connect example.com:443 -tls1_2
# TLS 1.3
openssl s_client -connect example.com:443 -tls1_3
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
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
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
如果你愿意,可以告诉我:
我可以给你更精确的测试命令。