Ubuntu 24.04 防火墙操作(iptables)
背景 Ubuntu 24.04 默认使用 nftables 作为底层防火墙,但 iptables 命令仍然可用(通过 iptables-nft 兼容层)。本文记录使用 iptables 管理端口的基本操作。 1. 查询当前开放的端口 iptables -L -n 输出示例: Chain INPUT (policy ACCEPT) target prot opt source destination ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 tcp dpt:22 ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 tcp dpt:80 ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 tcp dpt:443 如果想查看带行号的输出(方便后续删除),使用: iptables -L INPUT --line-numbers 2. 开启端口 2.1 添加规则 # 在 INPUT 链的第 5 条位置插入规则,放行 7777 端口 TCP 流量 iptables -I INPUT 5 -p tcp --dport 7777 -j ACCEPT 参数说明: ...