我们为服务器提供了 Chef,因此我们对 Ubuntu 16.04 和 18.04 版本具有相同的配置。恢复 iptables 规则也有相同的规则,
cat /etc/network/if-pre-up.d/iptables_load
/sbin/iptables-restore < /etc/iptables/general
但它不适用于 Ubuntu 18.04。
如果我手动运行它,它会起作用。这是否意味着此脚本未在启动时运行?
更新
我按照此处的描述创建了 systemd 服务,并且运行良好。
[Unit]
Description = Apply iptables rules
[Service]
Type=oneshot
ExecStart=/etc/network/if-pre-up.d/iptables_load
[Install]
WantedBy=network-pre.target
Run Code Online (Sandbox Code Playgroud)