在Linux系统下开启Telnet服务,可以按照以下步骤进行:
方法一:使用systemd(适用于大多数现代Linux发行版)
-
安装Telnet服务器软件包
- 对于基于Debian的系统(如Ubuntu):
sudo apt update sudo apt install xinetd telnetd
- 对于基于Red Hat的系统(如CentOS、Fedora):
sudo yum install xinetd telnet-server
- 对于基于Debian的系统(如Ubuntu):
-
启用并启动xinetd服务
- 启用xinetd服务以在系统启动时自动运行:
sudo systemctl enable xinetd
- 启动xinetd服务:
sudo systemctl start xinetd
- 启用xinetd服务以在系统启动时自动运行:
-
配置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 }
- 保存并退出编辑器。
- 编辑
-
重启xinetd服务以应用更改
sudo systemctl restart xinetd
-
验证Telnet服务是否运行
- 使用
netstat
或ss
命令检查端口23是否正在监听:sudo netstat -tuln | grep 23
或者sudo ss -tuln | grep 23
- 使用
方法二:使用init.d(适用于较旧的Linux发行版)
-
安装Telnet服务器软件包
- 对于基于Debian的系统:
sudo apt update sudo apt install xinetd telnetd
- 对于基于Red Hat的系统:
sudo yum install xinetd telnet-server
- 对于基于Debian的系统:
-
启用并启动xinetd服务
- 启用xinetd服务以在系统启动时自动运行:
sudo service xinetd start
- 设置开机自启:
sudo chkconfig xinetd on
- 启用xinetd服务以在系统启动时自动运行:
-
配置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 }
- 保存并退出编辑器。
- 编辑
-
重启xinetd服务以应用更改
sudo service xinetd restart
-
验证Telnet服务是否运行
- 使用
netstat
或ss
命令检查端口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服务。