温馨提示×

怎样在Linux下开启Telnet服务

小樊
42
2025-02-21 06:04:38
栏目: 智能运维
Linux服务器限时活动,0元免费领,库存有限,领完即止! 点击查看>>

在Linux系统下开启Telnet服务,可以按照以下步骤进行:

方法一:使用systemd(适用于大多数现代Linux发行版)

  1. 安装Telnet服务器软件包

    • 对于基于Debian的系统(如Ubuntu):
      sudo apt update
      sudo apt install xinetd telnetd
      
    • 对于基于Red Hat的系统(如CentOS、Fedora):
      sudo yum install xinetd telnet-server
      
  2. 启用并启动xinetd服务

    • 启用xinetd服务以在系统启动时自动运行:
      sudo systemctl enable xinetd
      
    • 启动xinetd服务:
      sudo systemctl start xinetd
      
  3. 配置xinetd以允许Telnet连接

    • 编辑/etc/xinetd.d/telnet文件:
      sudo nano /etc/xinetd.d/telnet
      
    • 确保文件内容如下(或类似配置):
      service telnet
      {
          disable = no
          socket_type = stream
          protocol = tcp
          wait = no
          user = root
          server = /usr/sbin/in.telnetd
          flags = REUSE
          port = 23
      }
      
    • 保存并退出编辑器。
  4. 重启xinetd服务以应用更改

    sudo systemctl restart xinetd
    
  5. 验证Telnet服务是否运行

    • 使用netstatss命令检查端口23是否正在监听:
      sudo netstat -tuln | grep 23
      
      或者
      sudo ss -tuln | grep 23
      

方法二:使用init.d(适用于较旧的Linux发行版)

  1. 安装Telnet服务器软件包

    • 对于基于Debian的系统:
      sudo apt update
      sudo apt install xinetd telnetd
      
    • 对于基于Red Hat的系统:
      sudo yum install xinetd telnet-server
      
  2. 启用并启动xinetd服务

    • 启用xinetd服务以在系统启动时自动运行:
      sudo service xinetd start
      
    • 设置开机自启:
      sudo chkconfig xinetd on
      
  3. 配置xinetd以允许Telnet连接

    • 编辑/etc/xinetd.d/telnet文件:
      sudo nano /etc/xinetd.d/telnet
      
    • 确保文件内容如下(或类似配置):
      service telnet
      {
          disable = no
          socket_type = stream
          protocol = tcp
          wait = no
          user = root
          server = /usr/sbin/in.telnetd
          flags = REUSE
          port = 23
      }
      
    • 保存并退出编辑器。
  4. 重启xinetd服务以应用更改

    sudo service xinetd restart
    
  5. 验证Telnet服务是否运行

    • 使用netstatss命令检查端口23是否正在监听:
      sudo netstat -tuln | grep 23
      
      或者
      sudo ss -tuln | grep 23
      

注意事项

  • Telnet协议不安全,因为它传输的数据是明文的。建议在生产环境中使用更安全的SSH协议。
  • 确保防火墙允许端口23的流量。例如,在使用iptables的情况下:
    sudo iptables -A INPUT -p tcp --dport 23 -j ACCEPT
    
    在使用firewalld的情况下:
    sudo firewall-cmd --permanent --add-service=telnet
    sudo firewall-cmd --reload
    

通过以上步骤,你应该能够在Linux系统下成功开启Telnet服务。

亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>

推荐阅读:Debian下如何开启Telnet服务

0