在 Linux 下使用 telnet 做测试,通常用于:
下面按常见场景说明。
很多 Linux 默认不装 telnet 客户端:
# CentOS / RHEL
yum install -y telnet
# Ubuntu / Debian
apt-get update
apt-get install -y telnet
telnet <IP或域名> <端口>
telnet www.baidu.com 80
Trying 180.101.50.242...
Connected to www.baidu.com.
Escape character is '^]'.
Trying 180.101.50.242...
telnet: connect to address 180.101.50.242: Connection refused
或Connection timed out
✅ Connected = 端口通
❌ refused / timeout = 端口不通或被防火墙拦截
telnet www.example.com 80
连接成功后,手动输入(⚠️ 不能回退,要一次输对):
GET / HTTP/1.1
Host: www.example.com
(最后一定要空一行)
你会看到服务器返回的 HTTP 响应。
telnet smtp.example.com 25
然后可以输入:
HELO test.com
MAIL FROM:<a@test.com>
RCPT TO:<b@test.com>
DATA
Subject: test
hello
.
QUIT
telnet 127.0.0.1 6379
输入:
PING
返回:
+PONG
Ctrl + ]
然后输入:
quit
nc / curl / openssl s_client# 测试端口(推荐)
nc -vz ip port
# 测试 HTTP
curl -v http://ip:port
# 测试 HTTPS
openssl s_client -connect ip:443
如果你有 具体服务或端口(如 MySQL、SSH、Kafka、Docker),我可以给你 对应的 telnet 测试命令。