Debian '忽略' /etc/network/if-pre-up.d/iptables

Che*_*ron 15 networking debian iptables

我希望我的 iptables 规则在启动时自动加载。根据 Debian 上的 wiki,这可以通过在 /etc/network/if-pre-up.d/ 中放置一个名为 iptables 的脚本来完成,所以我做到了,这就是它的样子:

cat /etc/network/if-pre-up.d/iptables 
#!/bin/sh
/sbin/iptables-restore < /etc/firewall/iptables.rules
/sbin/ip6tables-restore < /etc/firewall/ip6tables.rules
Run Code Online (Sandbox Code Playgroud)

这个脚本有效:如果我以 root 身份运行它,我的防火墙规则就会被应用。但是在重新启动时没有防火墙规则。我究竟做错了什么?

根据要求:/etc/network/interfaces(我没有碰过这个文件)

user@DebianVPS:~$ cat /etc/network/interfaces 
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).

# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
allow-hotplug eth0
iface eth0 inet dhcp
Run Code Online (Sandbox Code Playgroud)

epp*_*uig 11

此问题可能与脚本的权限位有关。这个命令的输出是什么?它包括你的文件吗?

run-parts --test /etc/network/if-pre-up.d
Run Code Online (Sandbox Code Playgroud)

  • 现在您发布了您的“接口”,我看到您没有使用 ifupdown,而是使用网络管理器。这就是不调用您的脚本的原因。请查看此文档:http://ubuntuforums.org/showthread.php?t=1084308 (3认同)
  • run-parts 对脚本的名称有点挑剔,在我的情况下,文件名中有一个点会导致脚本在启动时被忽略。 (3认同)

daw*_*wud 7

iptables-persistent包用于此任务。

/etc/iptables/rules.4和 中定义您的规则,/etc/iptables/rules.6不要忘记激活服务(使用update-rc.dchkconfig或者您最喜欢的工具。