系統(tǒng)升級到CentOS 7后總感覺iptables怪怪的,比如不管怎么保存重啟后都被初始化一下,即便我最后發(fā)大絕招啟動時候加命令:
首先iptables-save > /etc/iptables.rules保存當(dāng)前狀態(tài)。
然后再在/etc/rc.local中強(qiáng)制加上
/etc/rc.local
iptables-restore /etc/iptables .rules
重啟后雖然規(guī)則生效但仔細(xì)看規(guī)則還是一些被莫名添加的額外的內(nèi)容,讓人很是不爽。
仔細(xì)一google,發(fā)現(xiàn)問題之所在了。RedHat在7中更改了系統(tǒng)軟件,不再使用iptables作為系統(tǒng)的防火墻,而是使用了FirewallD,但是為了兼容過去的命令也可以使用iptables來設(shè)置防護(hù)規(guī)則,但啟動的時候自搞了一套。
解決方法也很簡單。
首先,可以考慮follow官方的想法轉(zhuǎn)用FirewallD。其實查看一些官方文檔也能用。
但是,個人覺得若沒有顯著的提升也可以繼續(xù)使用原來的iptables。若打算繼續(xù)使用iptables, 可以繼續(xù)做如下:
備份當(dāng)前規(guī)則
1 iptables-save > iptables.rules
禁用FireWallD,安裝&啟用iptables-services systemctl stop firewalld systemctl mask firewalld yum install iptables-services -y systemctl enable iptables
這時候檢查iptables發(fā)現(xiàn)規(guī)則被清空了
1 iptables -L -x -n
將備份的規(guī)則還原
1 iptables-restore iptables.rules
保存當(dāng)前規(guī)則
1 /usr/libexec/iptables/iptables .init save
若使用minimize版本的安裝,可能會出現(xiàn)提示
iptables: Saving firewall rules to /etc/sysconfig/iptables: /etc/init.d/iptables: line 274: restorecon: command not found
這是因為selinux沒有安裝的緣故,缺少一個組件。安裝policycoreutils即可。
1 yum install policycoreutils -y



















