问题原文
原帖链接 · Coul · CC BY-SA 4.0
We provision servers with chef so we have same configuration for Ubuntu 16.04 and 18.04 versions.
And there is same rule for restoring iptables rules
cat /etc/network/if-pre-up.d/iptables_load
/sbin/iptables-restore < /etc/iptables/general
but it doesn't work for Ubuntu 18.04.
If I run it manually it works. Does it mean this script isn't running at startup?
UPDATE
I created systemd service as it is described here and it works fine.
[Unit]
Description = Apply iptables rules
[Service]
Type=oneshot
ExecStart=/etc/network/if-pre-up.d/iptables_load
[Install]
WantedBy=network-pre.target
社区高分解答
原帖链接 · Csimbi · CC BY-SA 4.0
Here's what I did:
- Drop your iptables.rules into /etc/iptables.rules
Create service template like so:
sudo nano /etc/systemd/system/restore-iptables-rules.serviceCopy-paste this:
[Unit] Description = Apply iptables rules [Service] Type=oneshot ExecStart=/bin/sh -c 'iptables-restore < /etc/iptables.rules' [Install] WantedBy=network-pre.targetEnable service like so:
sudo systemctl enable restore-iptables-rules.serviceReboot and check that the rules have been applied:
sudo iptables -L
摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。
