在CentOS/RHEL/Scientific Linux 6 & 7 上安装Telnet


说明:

在安装和使用Telnet之前,需要记住以下几点。

  • 在公网(WAN)中使用Telnet是非常不好的想法。它会以明文的格式传输登入数据。每个人都可以看到明文。

  • 如果你还是需要Telnet,强烈建议你只在局域网内部使用。

  • 你可以使用SSH作为替代方法。但是确保不要用root用户登录。

Telnet定义:

Telnet 是用于通过TCP/IP网络远程登录计算机的协议。一旦与远程计算机建立了连接,它就会成为一个虚拟终端且允许你与远程计算机通信。

安装Telnet:

  1. yum安装telnet和telnet-server

    [root@rhel7 ~]# yum install -y telnet telnet-server

    现在telnet已经安装在你的服务器上了。

  2. 编辑文件/etc/xinetd.d/telnet

    [root@ceshiji ~]# vim /etc/xinetd.d/telnet

    设置 disable = nowKioL1mpbj3SxxuqAAAo8e7KM04147.png

    保存并退出文件。

    说明:我们不必在Linux 7做这步,原因如下图:

    Yum 安装telnet-server区别:

    Linux6安装telnet-server时有xinetd依赖包被安装,而Linux7并没有xinetd依赖包被安装!

    wKiom1mpb0CTITcHAAAY2ix15Xw643.png

    Linux7

    wKioL1mpbymCqzzGAAAavNjRRp4238.png

  3. 开启telnet服务

    在Linux 6系统中:

    [root@ceshiji ~]# service xinetd start

    在Linux7系统中:

    [root@rhel7 ~]# systemctl start telnet.socket

  4. 开机自启动telnet服务

    在Linux 6系统中:

    [root@ceshiji ~]# chkconfig telnet on

    [root@ceshiji ~]# chkconfig xinetd on

    在Linux7系统中:

    [root@rhel7 ~]# systemctl enable telnet.socket

  5. 查看telnet服务运行状态

    在Linux 6系统中:

    [root@ceshiji ~]# service xinetd status 或 [root@ceshiji ~]# /etc/init.d/xinetd status

    在Linux7系统中:

    [root@rhel7 ~]# service telnet.socket status 或 [root@rhel7 ~]# systemctl status telnet.socket

  6. telnet默认的端口是23,查看侦听端口

    在Linux 6系统中:

    wKiom1mpdUPSx2v2AAAO2-eyQTU793.png

    在Linux 7系统中:

    wKioL1mpdULw15caAAAO2wsBnYc615.png

  7. iptables与firewall的配置:

    说明:

    (1)如果不使用iptables与firewall可以将它们关闭,关闭的命令如下:

       [root@ceshiji ~]# iptables -F

       [root@ceshiji ~]# /etc/init.d/iptables stop   

       [root@rhel7 ~]# systemctl stop firewalld

       [root@rhel7 ~]# systemctl disable firewalld

    (2)Linux7中不再有iptables,使用firewalld;在Linux7中安装并使用iptables的方法如下:

       [root@rhel7 ~]# yum install -y iptables-services

       开启iptables服务:

       [root@rhel7 ~]# systemctl start iptables

       查看iptables服务运行状态:

       [root@rhel7 ~]# systemctl status iptables

       开机自启动iptables服务:

       [root@rhel7 ~]# systemctl enable iptables

       使用iptables:

       [root@rhel7 ~]# vim /etc/sysconfig/iptables

       加入如下行“-A INPUT -p tcp -m state --state NEW --dport 23 -j ACCEPT”

    wKioL1muTCiRupnZAABAj_QxkHo780.png

    说明:上面只是演示下linux7中iptables安装和使用,实际工作中在linux7中,我们使用的是firewall!

    (3)开启iptables和firewall,让telnet的默认端口23可以通过防火墙和路由器。

       在Linux 6系统中:

       [root@ceshiji ~]# vim /etc/sysconfig/iptables

       加入如下行“-A INPUT -p tcp -m state --state NEW --dport 23 -j ACCEPT”wKioL1muULuwqK-3AABAj_QxkHo262.png

       保存退出!重启iptables服务。     

       [root@ceshiji ~]# service iptables restart

       在Linux 7系统中:

       [root@rhel7 ~]# firewall-cmd --permanent --add-port=23/tcp

       [root@rhel7 ~]# firewall-cmd --reload

  8. 测试

    [root@ceshiji ~]# yum install -y telnet  

    说明:客户端上安装telnet包

    [root@rhel7 ~]# telnet 192.169.5.121

    wKiom1muVaWy1flrAAAoRpp61Os162.png

    完成!