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


CentOS7中執行

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=<zone>] --add-port=<port>[-<port>]/<protocol> [--timeout=<seconds>]
此舉將啟用端口和協議的組合。端口可以是一個單獨的端口 <port> 或者是一個端口范圍 <port>-<port> 。協議可以是 tcp 或 udp。
實際命令如下:
firewall-cmd --permanent --add-port=1000-2000/tcp
執行可以成功
用該命令查詢firewall-cmd --permanent --query-port=1000/tcp

 

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

執行一下命令:

 

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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM