温馨提示×

linux telnet如何防火墙

小樊
44
2026-10-15 07:52:50
栏目: 智能运维

在 Linux 下,“telnet 如何防火墙”通常有两种理解,我分别说明:


一、用防火墙限制/禁止 telnet(安全角度)

telnet 默认端口是 23,且明文传输,极不安全,生产环境建议直接禁用或限制。

1. 使用 firewalld(CentOS / RHEL / Rocky / Alma)

# 禁止 telnet 端口
firewall-cmd --permanent --remove-service=telnet
firewall-cmd --permanent --add-port=23/tcp --zone=public
firewall-cmd --permanent --remove-port=23/tcp
firewall-cmd --reload

只允许特定 IP:

firewall-cmd --permanent --add-rich-rule='
rule family="ipv4" source address="192.168.1.100" port protocol="tcp" port="23" accept'
firewall-cmd --reload

2. 使用 iptables

# 禁止 telnet
iptables -A INPUT -p tcp --dport 23 -j DROP

# 只允许某个 IP
iptables -A INPUT -p tcp --dport 23 -s 192.168.1.100 -j ACCEPT
iptables -A INPUT -p tcp --dport 23 -j DROP

保存:

service iptables save   # CentOS 6
# 或
iptables-save > /etc/sysconfig/iptables

3. 直接禁用 telnet 服务

systemctl stop telnet.socket
systemctl disable telnet.socket

二、telnet 被防火墙挡了,如何放通(使用角度)

如果你要用 telnet ip port 测试连通性:

# firewalld
firewall-cmd --permanent --add-port=23/tcp
firewall-cmd --reload

# iptables
iptables -A INPUT -p tcp --dport 23 -j ACCEPT

三、强烈建议

✅ 不要用 telnet 做远程登录
✅ 用 SSH(22端口) 替代

ssh user@ip

如果你能说明:

  • 用的是 CentOS / Ubuntu / 麒麟 / 欧拉?
  • 是想 禁 telnet 还是 放通 telnet?

我可以给你更精确的命令。

0 踩