CentOS 7 :Failed to start IPv4 firewall with iptables.


用iptables開啟防火牆報錯: Failed to start  IPv4 firewall with iptables.

轉載於:https://blog.csdn.net/ls1645/article/details/78750561

    錯誤原因:因為centos7.0默認不是使用iptables方式管理,而是firewalld方式。CentOS6.0防火牆用iptables管理。

        解決辦法有兩個:使用firewalld方式。或者關閉firewalld,然后安裝iptables。

一、關閉firewalld,安裝iptables過程:

停止並屏蔽firewalld:

  

  systemctl stop firewalld

  systemctl mask firewalld

 

安裝iptables-services:

  

  yum install iptables-services

 

設置開機啟動:

 

  systemctl enable iptables

 

停止/啟動/重啟 防火牆:

systemctl [stop|start|restart] iptables

#or

service iptables [stop|start|restart]

保存防火牆配置:

 

service iptables save

#or

/usr/libexec/iptables/iptables.init save

 

 

     按照上述命令配置后的界面:

 

 

 

二、從iptables切換回firewalld

    1、先看firewalld的狀態:inactive

     

    2、安裝firewalld

   3、切換到firewalld,切換過程與切換iptables一樣

 

/************下面是iptables的一些命令*******************************/

查詢防火牆狀態:

[root@localhost ~]# service  iptables status

停止防火牆:

[root@localhost ~]# service  iptables stop 

啟動防火牆:

[root@localhost ~]# service  iptables start 

重啟防火牆:

[root@localhost ~]# service  iptables restart 

永久關閉防火牆:

[root@localhost ~]# chkconfig  iptables off 

永久關閉后啟用:

[root@localhost ~]# chkconfig  iptables on

開啟端口:

[root@localhost ~]# vim/etc/sysconfig/iptables

/**********下面是firewalld的一些命令*****************************/

#systemctl statusfirewalld  //查看狀態,看電腦上是否已經安裝firewalld

#yum installfirewalld  //安裝firewalld防火牆

#systemctl startfirewalld.service   //開啟防火牆

#systemctl stop firewalld.service  //關閉防火牆

#systemctl enable firewalld.service //設置開機自動啟動

#systemctl disable firewalld.service  //設置關閉開機制動啟動

#firewall-cmd--reload  //在不改變狀態的條件下重新加載防火牆

啟用某個服務

#firewall-cmd --zone=public --add-service=https  //臨時

#firewall-cmd --permanent --zone=public --add-service=https  //永久

開啟某個端口

#firewall-cmd--permanent --zone=public --add-port=8080-8081/tcp  //永久

#firewall-cmd  --zone=public --add-port=8080-8081/tcp   //臨時

查看開啟的端口和服務

#firewall-cmd--permanent --zone=public --list-services   //服務空格隔開 例如 dhcpv6-client https ss  

#firewall-cmd--permanent --zone=public --list-ports //端口空格隔開  例如 8080-8081/tcp 8388/tcp 80/tcp

#systemctl restartfirewalld.service  //修改配置后需要重啟服務使其生效

#firewall-cmd--zone=public --query-port=8080/tcp //查看服務是否生效(例:添加的端口為8080)

 

 

/**********下面是systemctl的一些命令*******************************/

 

        觀察iptables和firewalld使用的兩組命令,發現三個常用的命令:service、chkconfig、systemctl。那么它們分別是做什么的呢?(去網上搜索了一下給出了答案)

        systemctl命令是系統服務管理器指令,它實際上將 service 和 chkconfig 這兩個命令組合到一起。

 

任務

舊指令

新指令

使某服務自動啟動

chkconfig --level 3 httpd on

systemctl enable httpd.service

使某服務不自動啟動

chkconfig --level 3 httpd off

systemctl disable httpd.service

檢查服務狀態

service httpd status

systemctl status httpd.service(服務詳細信息) 

systemctl is-active httpd.service(僅顯示是否 Active)

顯示所有已啟動的服務

chkconfig --list

systemctl list-units --type=service

啟動某服務

service httpd start

systemctl start httpd.service

停止某服務

service httpd stop

systemctl stop httpd.service

重啟某服務

service httpd restart

systemctl restart httpd.service

 

 

總結:

        記是記不住的,實操才可以,熟能生巧。

        抓住一個問題,深入去挖,往往能挖出一片,從而掃清一片盲點。深挖能出清泉。

參考文章: 

https://www.vkilo.com/rhel-7-iptables-service.html

http://blog.csdn.net/Joe68227597/article/details/75207859 

http://www.linuxidc.com/Linux/2012-06/63111.html

http://man.linuxde.net/systemctl


免責聲明!

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



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