ubuntu开机自动加载iptables配置(转)

原文:http://www.xuebuyuan.com/730127.html

 

iptables的使用参见http://wiki.ubuntu.org.cn/IptablesHowTo

iptables配置完成后,规则是自动立即生效的,但是机器重启动后,规则会丢失

ubuntu下可以通过以下步骤保存iptables设置,并实现开机自动加载

1、iptables配置完成后手动保存

执行iptables-save > /etc/iptables.rules ,将当前配置保存再iptables.rules文件中,文件名可以随意。

该命令要切换到root用户执行,sudo会提示无权限,或者你修改/etc/iptables.up.rules的权限,

sudo chmod a+w /etc/iptables.rules,然后就可以直接执行iptables-save > /etc/iptables.rules了

查看该文件可以发现里面记录的就是iptables规则。

2、修改网卡配置文件

在网卡IP配置文件/etc/network/interfaces末行加入一行pre-up iptables-restore < /etc/iptables.rules

其中:/etc/iptables.rules是第一步中自定义的配置文件位置和名称


3、 重启服务器验证

原文地址:https://www.cnblogs.com/ajianbeyourself/p/4821424.html