重新加载iptables

我在Ubuntu的/etc/iptables/filter中对iptables配置文件进行了更改,并想重新加载它们。 我阅读了手册页并且也用谷歌搜索但找不到相关信息。 任何帮助将不胜感激。

最简单的方法是重启(如果下面不起作用,重启,检查是否进行了更改)。

第二个最简单的方法是使用iptables配置重启守护进程(google:restart daemon ubuntu)。

示例(取决于您的配置):

 /etc/init.d/iptables restart /etc/init.d/networking restart /etc/init.d/firewall restart 

通常,您的防火墙规则位于配置文件/etc/iptables.firewall.rules

要激活文件中定义的规则,必须将它们发送到iptables-restore (如果需要,可以使用其他文件):

 sudo iptables-restore < /etc/iptables.firewall.rules 

你可以检查它们是否被激活:

 sudo iptables -L 

如果要在每次启动计算机时激活相同的规则,请创建此文件:

 sudo nano /etc/network/if-pre-up.d/firewall 

有了这个内容:

 #!/bin/sh /sbin/iptables-restore < /etc/iptables.firewall.rules 

并允许执行:

 sudo chmod +x /etc/network/if-pre-up.d/firewall 

希望它可以帮助你=)

/etc/iptables.firewall.rules示例文件:

 *filter # Allow all loopback (lo0) traffic and drop all traffic to 127/8 that doesn't use lo0 -A INPUT -i lo -j ACCEPT -A INPUT -d 127.0.0.0/8 -j REJECT # Accept all established inbound connections -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT # Allow all outbound traffic - you can modify this to only allow certain traffic -A OUTPUT -j ACCEPT # Allow HTTP and HTTPS connections from anywhere (the normal ports for websites and SSL). -A INPUT -p tcp --dport 80 -j ACCEPT -A INPUT -p tcp --dport 443 -j ACCEPT # Allow SSH connections # # The -dport number should be the same port number you set in sshd_config # -A INPUT -p tcp -m state --state NEW --dport 22 -j ACCEPT # Allow ping -A INPUT -p icmp -j ACCEPT # Log iptables denied calls -A INPUT -m limit --limit 5/min -j LOG --log-prefix "iptables denied: " --log-level 7 # Drop all other inbound - default deny unless explicitly allowed policy -A INPUT -j DROP -A FORWARD -j DROP COMMIT 

如果您已执行规则,则它们已在运行,无需重新加载。 如果你有一个配置文件,但它没有被执行过最好的方式我到目前为止看到的是使用iptables-apply (一个iptables扩展)。

 iptables-apply -t 60 your_rules_file 

这将应用规则60秒(默认为10),如果您不确认,则还原它们。 这将节省您,以防因为规则而被抛出系统(例如,如果您通过ssh操作)。

您可以使用以下内容作为替代:

 iptables-restore < your_rules_file; sleep 60; iptables-restore < clean_rules 

谷歌搜索后,这是我发现重新启动iptables。 。 。 sudo /etc/init.d/firewall restart

如果您想重新加载IPtables以validation您刚刚做出的更改; 您还可以使用以下命令行重启Apache:

/etc/init.d/apache2停止

/etc/init.d/apache2 start

这些命令可能会有所不同,具体取决于您的Ubuntu风格,以及之前可能进行的最终修改。

希望这可以帮助。

皮埃尔