Linux常用命令-telnet

命令

telnet

描述

user interface to the TELNET protocol
TELNET协议工具,用于远程登录

用法

1
2
telnet  [-4] [-6] [-8] [-E] [-L] [-S tos] [-a] [-c] [-d] [-e char] [-l user]
[-n tracefile] [-b hostalias ] [-r] [host-name [port]]

选项

1
2
3
4
5
6
7
8
9
10
11
Options:
-4 使用IPv4地址
-6 使用IPv6地址
-E 阻止任何字符被识别为转义字符
-d 开启debug
-K 不自动登录到远程系统
-l 指定用户名
-a 尝试自动登录
-e 指定转移字符
-n 打开tracefile以记录跟踪信息
-x 加密数据

注意

注意telnet数据是明文传输的,推荐仅用于连接测试,建议远程连接使用ssh工具

示例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# 测试目标IP和端口连接正常
$ telnet 192.168.31.80 80
Trying 192.168.31.80...
Connected to 192.168.31.80.
Escape character is '^]'.
^CConnection closed by foreign host.
# 无法连接,目标IP可能没有启用指定的监听端口
$ telnet 192.168.31.80 8088
Trying 192.168.31.80...
telnet: connect to address 192.168.31.80: Connection refused

$ telnet www.baidu.com 80
Trying 110.242.68.4...
Connected to www.baidu.com.
Escape character is '^]'.
HTTP/1.1 400 Bad Request
Connection closed by foreign host.
# 连接超时,原因很多
$ telnet www.baidu.com 8088
Trying 110.242.68.3...
telnet: connect to address 110.242.68.3: Connection timed out
Trying 110.242.68.4...
telnet: connect to address 110.242.68.4: Connection timed out

# 查看目标ssh协议版本
$ telnet 127.0.0.1 22
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.
SSH-2.0-OpenSSH_7.4