iptables 列表不会在重启后持续存在

Bob*_*der 3 iptables centos whitelist cloudflare

我正在尝试通过发出以下命令将 CloudFlare 的 IP 地址列入我服务器上的白名单:

iptables -N whitelist
iptables -A whitelist -s 204.93.177.0/24 -j ACCEPT
iptables -A whitelist -s 199.27.128.0/21 -j ACCEPT
iptables -A whitelist -s 173.245.48.0/20 -j ACCEPT
iptables -A whitelist -s 103.22.200.0/22 -j ACCEPT
iptables -A whitelist -s 141.101.64.0/18 -j ACCEPT
iptables -A whitelist -s 108.162.192.0/18 -j ACCEPT
Run Code Online (Sandbox Code Playgroud)

当我输入:iptables -L我看到:

Chain whitelist (0 references)
target     prot opt source               destination
ACCEPT     all  --  network/24           anywhere
ACCEPT     all  --  199.27.128.0/21      anywhere
ACCEPT     all  --  173.245.48.0/20      anywhere
ACCEPT     all  --  103.22.200.0/22      anywhere
ACCEPT     all  --  141.101.64.0/18      anywhere
ACCEPT     all  --  108.162.192.0/18     anywhere
Run Code Online (Sandbox Code Playgroud)

然后我通过执行service iptables restart. 但是,没有任何改变,也没有将这些 IP 列入白名单 :( 我错过了什么吗?

mal*_*pdx 8

重启前需要保存配置。在 Redhat 系统上,这在 /etc/sysconfig/iptables 中。最简单的方法是:

  • 发出你的命令
  • 运行iptables -L以检查配置
  • service iptables save
  • 运行service iptables restart重新加载
  • 再次检查配置 iptables -L