Linux 命令 | telnet

telnet 是登录远程服务器的一种工具。

不过所有通信都是明文发送,不会加密。

因此一般不会用来登录远程服务器,不过可以调试远程连接问题


用法

telnet <hostname or ip> <port>

  • hostname 远程连接的域名

  • ip 远程连接 IP

  • port 远程连接端口

  • 例:

# telnet 10.100.xxx.xxx 514
Trying 10.100.xxx.xxx...
Connected to 10.100.xxx.xxx.
Escape character is '^]'.

常见问题

连接超时

# telnet 10.100.xxx.xxx 514
Trying 10.100.xxx.xxx...
telnet: connect to address 10.100.xxx.xxx: Connection timed out
  • 表示telnet 没有收到请求连接的响应

  • 可能的原因

    • ①和服务器之间的路由器挂了

    • ②防火墙拦截请求

  • 解决方案

    • 针对原因①,用mtr 10.100.xxx.xxx确认服务器是否可达

    • 针对原因②,检查防火墙iptables -L -v -n,或者关闭防火墙确认

提示域名不存在

# telnet hhhhh 514
telnet: hhhhh: Name or service not known
hhhhh: Unknown host
  • 表示域名 DNS 设定有问题,可以把域名换成 IP 进一步确认

  • 可能的原因

    • 域名解析问题,和 ip 不匹配,解析记录不正确,域名过期等
  • 解决方案

    • 检查 DNS 解析内容

连接被拒绝

# telnet www.xxx.com 567
Trying www.xxx.com...
telnet: Unable to connect to remote host: Connection refused
  • 表示服务器可达,但端口没有开发

  • netstat -tlunp确认端口状态

  • 查看远程服务器的相关服务是否运行正常ps auxf

连接被远程服务器关闭

# telnet 10.100.xxx.xxx 514
Trying 10.100.xxx.xxx...
Connected to 10.100.xxx.xxx.
Escape character is '^]'.
Connection closed by foreign host.
  • 表示可以连通,但远程服务器有安全组设置,限制了连接

  • 去远程服务器查看端口对应的服务是否有限制

posted @ 2023-02-03 17:28  菜乌  阅读(3711)  评论(0编辑  收藏  举报