一、安装telnet客户端
1.检查下linux版本
[root@master-mysql ~]# cat /etc/redhat-release
CentOS Linux release 8.4.2105
2.检查是否已经安装telnet
[root@master-mysql ~]# rpm -qa | grep telnet
[root@master-mysql ~]#
3.搜索telnet软件包
[root@master-mysql ~]# yum list telnet*
Last metadata expiration check: 0:40:53 ago on Fri 03 Dec 2021 09:30:05 PM HKT.
Available Packages
telnet.x86_64 1:0.17-76.el8 appstream
telnet-server.x86_64 1:0.17-76.el8 appstream
[root@master-mysql ~]# yum search telnet*
Last metadata expiration check: 0:42:12 ago on Fri 03 Dec 2021 09:30:05 PM HKT.
============================ Name Matched: telnet* =============================
telnet.x86_64 : The client program for the Telnet remote login protocol
telnet-server.x86_64 : The server program for the Telnet remote login protocol
[root@master-mysql ~]#
4.安装telnet软件包
[root@master-mysql ~]# yum install -y telnet.x86_64
Last metadata expiration check: 0:45:54 ago on Fri 03 Dec 2021 09:30:05 PM HKT.
Dependencies resolved.
================================================================================
Package Architecture Version Repository Size
================================================================================
Installing:
telnet x86_64 1:0.17-76.el8 appstream 72 k
Transaction Summary
================================================================================
Install 1 Package
Total download size: 72 k
Installed size: 119 k
Downloading Packages:
telnet-0.17-76.el8.x86_64.rpm 294 kB/s | 72 kB 00:00
--------------------------------------------------------------------------------
Total 108 kB/s | 72 kB 00:00
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
Preparing : 1/1
Installing : telnet-1:0.17-76.el8.x86_64 1/1
Running scriptlet: telnet-1:0.17-76.el8.x86_64 1/1
Verifying : telnet-1:0.17-76.el8.x86_64 1/1
Installed:
telnet-1:0.17-76.el8.x86_64
Complete!
[root@master-mysql ~]#
5.验证测试
[root@master-mysql ~]# telnet www.sina.com.cn 80
Trying 140.249.6.254...
Connected to www.sina.com.cn.
Escape character is '^]'.
^]
telnet> quit
Connection closed.
[root@master-mysql ~]#
转义符是 ‘^]’ 看了文章得知 ^ 代表 Ctrl ;现在明白了,就是提示按 Ctrl + ] 呼出 telnet 命令行,键入 quit 退出 telnet;
二、安装telnet服务端
服务端telnet-server由于安全原因由用户自主选择安装。
1.接着上面第4步安装telnet-server
[root@master-mysql ~]# yum install -y telnet-server.x86_64
Last metadata expiration check: 0:56:42 ago on Fri 03 Dec 2021 09:30:05 PM HKT.
Dependencies resolved.
================================================================================
Package Architecture Version Repository Size
================================================================================
Installing:
telnet-server x86_64 1:0.17-76.el8 appstream 48 k
Transaction Summary
================================================================================
Install 1 Package
Total download size: 48 k
Installed size: 57 k
Downloading Packages:
telnet-server-0.17-76.el8.x86_64.rpm 125 kB/s | 48 kB 00:00
--------------------------------------------------------------------------------
Total 57 kB/s | 48 kB 00:00
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
Preparing : 1/1
Installing : telnet-server-1:0.17-76.el8.x86_64 1/1
Running scriptlet: telnet-server-1:0.17-76.el8.x86_64 1/1
Verifying : telnet-server-1:0.17-76.el8.x86_64 1/1
Installed:
telnet-server-1:0.17-76.el8.x86_64
Complete!
[root@master-mysql ~]# rpm -qa | grep telnet
telnet-server-0.17-76.el8.x86_64
telnet-0.17-76.el8.x86_64
2.由于telnet由xinetd管理,xinetd添加telnet服务
[root@master-mysql ~]# rpm -qa | grep xinetd
[root@master-mysql ~]# yum list xinetd
Last metadata expiration check: 1:24:57 ago on Fri 03 Dec 2021 09:30:05 PM HKT.
Available Packages
xinetd.x86_64 2:2.3.15-24.el8 appstream
[root@master-mysql ~]# yum search xinetd
Last metadata expiration check: 1:25:08 ago on Fri 03 Dec 2021 09:30:05 PM HKT.
========================= Name Exactly Matched: xinetd =========================
xinetd.x86_64 : A secure replacement for inetd
[root@master-mysql ~]# yum install -y xinetd.x86_64
[root@master-mysql ~]# rpm -qa | grep xinetd
xinetd-2.3.15-24.el8.x86_64
3.配置文件开启telnet服务
telnet服务安装之后,默认是不开启服务,修改文件/etc/xinetd.d/telnet来开启服务。如下图,在xinetd.d目下没有telnet文件
[root@master-mysql ~]# ll /etc/xinetd.d/
total 44
-rw------- 1 root root 1157 Nov 9 2019 chargen-dgram
-rw------- 1 root root 1159 Nov 9 2019 chargen-stream
-rw------- 1 root root 1157 Nov 9 2019 daytime-dgram
-rw------- 1 root root 1159 Nov 9 2019 daytime-stream
-rw------- 1 root root 1157 Nov 9 2019 discard-dgram
-rw------- 1 root root 1159 Nov 9 2019 discard-stream
-rw------- 1 root root 1148 Nov 9 2019 echo-dgram
-rw------- 1 root root 1150 Nov 9 2019 echo-stream
-rw------- 1 root root 1212 Nov 9 2019 tcpmux-server
-rw------- 1 root root 1149 Nov 9 2019 time-dgram
-rw------- 1 root root 1150 Nov 9 2019 time-stream
那么我们就需要使用 vi telnet 创建一个文件并写入以下内容保存即可,注意如果目录下存在telnet需要将 disable 修改为 disable = no 默认的disable = yes
[root@master-mysql ~]# vi /etc/xinetd.d/telnet
# default: yes
# description: The telnet server servestelnet sessions; it uses \
# unencrypted username/password pairs for authentication.
service telnet
{
flags = REUSE
socket_type = stream
wait = no
user = root
server =/usr/sbin/in.telnetd
log_on_failure += USERID
disable = no
}
4.重启xinetd服务
由于上面修改了telnet配置文件,需要重新启动下服务,看xinetd是否启动成功;
[root@master-mysql ~]# systemctl restart xinetd.service
[root@master-mysql ~]# ps -ef | grep xinetd
root 5669 1 0 23:10 ? 00:00:00 /usr/sbin/xinetd -stayalive -pidfile /var/run/xinetd.pid
root 5676 5164 0 23:10 pts/0 00:00:00 grep --color=auto xinetd
5.验证 telnet
telnet server安装配置完了,就需要验证下是否可以使用
telnet 10.85.1.39
输入账号密码如下图:
查看登录状态
[root@master-mysql ~]# systemctl status xinetd
● xinetd.service - Xinetd A Powerful Replacement For Inetd
Loaded: loaded (/usr/lib/systemd/system/xinetd.service; enabled; vendor preset: enabled)
Active: active (running) since Fri 2021-12-03 23:10:08 HKT; 24min ago
Docs: man:xinetd
man:xinetd.conf
man:xinetd.log
Main PID: 5669 (xinetd)
Tasks: 1 (limit: 11392)
Memory: 1.5M
CGroup: /system.slice/xinetd.service
└─5669 /usr/sbin/xinetd -stayalive -pidfile /var/run/xinetd.pid
Dec 03 23:10:08 master-mysql xinetd[5669]: removing discard
Dec 03 23:10:08 master-mysql xinetd[5669]: removing echo
Dec 03 23:10:08 master-mysql xinetd[5669]: removing echo
Dec 03 23:10:08 master-mysql xinetd[5669]: removing tcpmux
Dec 03 23:10:08 master-mysql xinetd[5669]: removing time
Dec 03 23:10:08 master-mysql xinetd[5669]: removing time
Dec 03 23:10:08 master-mysql xinetd[5669]: xinetd Version 2.3.15 started with loadavg labeled-networking options compiled i>
Dec 03 23:10:08 master-mysql xinetd[5669]: Started working: 1 available service
Dec 03 23:30:54 master-mysql xinetd[5669]: START: telnet pid=5720 from=::ffff:10.85.5.17
Dec 03 23:34:00 master-mysql xinetd[5669]: EXIT: telnet status=0 pid=5720 duration=186(sec)
若为安装telnet server 访问会报错
C:\Users\Administrator>telnet 10.85.1.211
正在连接10.85.1.211...无法打开到主机的连接。 在端口 23: 连接失败
6.设置开机启动
root@master-mysql ~]# systemctl enable xinetd.service
[root@master-mysql ~]# systemctl enable telnet.socket
Created symlink /etc/systemd/system/sockets.target.wants/telnet.socket → /usr/lib/systemd/system/telnet.socket.