天天看點

Linux 解決CentOS7關閉/開啟防火牆出現Unit iptables.service failed to load: No such file or directory.

轉載:http://blog.csdn.net/c233728461/article/details/52679558

CentOS7中執行

[plain] view plain copy

service iptables start/stop  

會報錯Failed to start iptables.service: Unit iptables.service failed to load: No such file or directory.

在CentOS 7或RHEL 7或Fedora中防火牆由firewalld來管理,

如果要添加範圍例外端口 如 1000-2000

文法指令如下:啟用區域端口和協定組合

firewall-cmd [--zone=] --add-port=[-]/ [--timeout=]

此舉将啟用端口和協定的組合。端口可以是一個單獨的端口 或者是一個端口範圍 - 。協定可以是 tcp 或 udp。

實際指令如下:

添加

firewall-cmd --zone=public --add-port=80/tcp --permanent (--permanent永久生效,沒有此參數重新開機後失效)

firewall-cmd --zone=public --add-port=1000-2000/tcp --permanent

重新載入

firewall-cmd --reload

檢視

firewall-cmd --zone= public --query-port=80/tcp

删除

firewall-cmd --zone= public --remove-port=80/tcp --permanent

當然你可以還原傳統的管理方式。

執行一下指令:

systemctl stop firewalld  

systemctl mask firewalld  

并且安裝iptables-services:

yum install iptables-services  

設定開機啟動:

systemctl enable iptables  

systemctl stop iptables  

systemctl start iptables  

systemctl restart iptables  

systemctl reload iptables  

儲存設定:

service iptables save  

OK,再試一下應該就好使了

開放某個端口 在/etc/sysconfig/iptables裡添加

-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 8080 -j ACCEPT

繼續閱讀