温馨提示×

Ubuntu telnet服务器搭建教程

小樊
42
2026-01-04 17:51:29
栏目: 云计算

Ubuntu Telnet 服务器搭建教程

一 环境准备与安装

  • 更新索引并安装服务组件(两种常见组合,二选一或同时安装以兼容不同配置):
    • 使用 xinetd 管理:sudo apt update && sudo apt install -y xinetd telnetd
    • 使用 inetd 管理:sudo apt update && sudo apt install -y inetd
  • 安装 telnet 客户端用于本机测试:sudo apt install -y telnet
  • 说明:部分 Ubuntu 版本在装完 telnetd 后会在 /etc/inetd.conf 自动写入一行提示,若系统采用 xinetd,需要将该行转换为 xinetd 配置格式(参考下文)。

二 配置方式

  • 方式 A xinetd(推荐)
    1. 确保主配置包含服务目录:编辑 /etc/xinetd.conf,确认存在或加入: includedir /etc/xinetd.d
    2. 创建服务文件 /etc/xinetd.d/telnet,内容示例: service telnet { disable = no flags = REUSE socket_type = stream wait = no user = root server = /usr/sbin/in.telnetd log_on_failure += USERID }
    3. 如需仅监听内网或限制来源,可加入:bind = 192.168.1.10;only_from = 192.168.1.0/24;no_access = 192.168.1.100
  • 方式 B inetd
    1. 编辑 /etc/inetd.conf,加入或确保存在: telnet stream tcp nowait telnetd /usr/sbin/tcpd /usr/sbin/in.telnetd
    2. 若系统实际使用 xinetd,请将上述 inetd 行转换为 xinetd 格式(或使用 xinetd 方式统一管理)。

三 启动与防火墙

  • 启动或重载服务:
    • xinetd:sudo systemctl restart xinetd 或 sudo systemctl reload xinetd
    • inetd:sudo systemctl restart inetd
  • 防火墙放行(默认端口 23/TCP):
    • ufw:sudo ufw allow 23/tcp 或 sudo ufw allow telnet
    • firewalld:sudo firewall-cmd --permanent --add-service=telnet && sudo firewall-cmd --reload
  • 验证监听:sudo ss -lntp | grep :23(应看到 0.0.0.0:23 或 :::23 处于 LISTEN)。

四 测试与登录

  • 本机测试:telnet 127.0.0.1
  • 远程测试:telnet 服务器IP 23
  • 登录建议:优先使用普通用户登录,必要时再切换 root。若需允许 root 登录,可临时将 /etc/securetty 重命名(如 mv /etc/securetty /etc/securetty.bak)或在 /etc/pam.d/login 注释 pam_securetty 行;出于安全考虑不建议长期开放 root 的 telnet 登录。

五 安全与替代方案

  • 风险提示:Telnet 传输为明文,用户名与口令可被窃听,生产环境不建议启用;如必须使用,请仅在内网、受控网段、临时调试场景开启,并配合防火墙与来源限制(如 only_from、no_access)。
  • 更优替代:使用 SSH(OpenSSH),安装:sudo apt install -y openssh-server;连接:ssh 用户名@服务器IP。SSH 提供加密通道与更强的身份认证能力。

0