CentOS7/6 關閉防火牆


CentOS6關閉防火牆使用以下命令,

//臨時關閉
service iptables stop
//禁止開機啟動
chkconfig iptables off

CentOS7中若使用同樣的命令會報錯,

stop  iptables.service
Failed to stop iptables.service: Unit iptables.service not loaded.

這是因為CentOS7版本后防火牆默認使用firewalld,因此在CentOS7中關閉防火牆使用以下命令,

//臨時關閉
systemctl stop firewalld
//禁止開機啟動
systemctl disable firewalld
Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.

 1、firewalld的基本使用

啟動: systemctl start firewalld
關閉: systemctl stop firewalld
查看狀態: systemctl status firewalld 
開機禁用  : systemctl disable firewalld
開機啟用  : systemctl enable firewalld
 
 
2.systemctl是CentOS7的服務管理工具中主要的工具,它融合之前service和chkconfig的功能於一體。

啟動一個服務:systemctl start firewalld.service
關閉一個服務:systemctl stop firewalld.service
重啟一個服務:systemctl restart firewalld.service
顯示一個服務的狀態:systemctl status firewalld.service
在開機時啟用一個服務:systemctl enable firewalld.service
在開機時禁用一個服務:systemctl disable firewalld.service
查看服務是否開機啟動:systemctl is-enabled firewalld.service
查看已啟動的服務列表:systemctl list-unit-files|grep enabled
查看啟動失敗的服務列表:systemctl --failed

3.配置firewalld-cmd

查看版本: firewall-cmd --version
查看幫助: firewall-cmd --help
顯示狀態: firewall-cmd --state
查看所有打開的端口: firewall-cmd --zone=public --list-ports
更新防火牆規則: firewall-cmd --reload
查看區域信息:  firewall-cmd --get-active-zones
查看指定接口所屬區域: firewall-cmd --get-zone-of-interface=eth0
拒絕所有包:firewall-cmd --panic-on
取消拒絕狀態: firewall-cmd --panic-off
查看是否拒絕: firewall-cmd --query-panic
 
那怎么開啟一個端口呢
添加
firewall-cmd --zone=public --add-port=80/tcp --permanent    (--permanent永久生效,沒有此參數重啟后失效)
重新載入
firewall-cmd --reload
查看
firewall-cmd --zone= public --query-port=80/tcp
刪除
firewall-cmd   --remove-port=80/tcp --permanent
---------------------------------------------------------------------------
centos6關閉防火牆
先進入init.d目錄,命令如下:
[root@centos6 ~]# cd /etc/init.d/

[root@centos6 init.d]#

然后
查看防火牆狀態:
[root@centos6 init.d]# /etc/init.d/iptables status

暫時關閉防火牆:
[root@centos6 init.d]# /etc/init.d/iptables stop

重啟iptables:
[root@centos6 init.d]# /etc/init.d/iptables restart
 
centos6 開啟端口:
寫入修改
        /sbin/iptables -I INPUT -p tcp --dport 80 -j ACCEPT   
保存修改 
         /etc/init.d/iptables save   
 重啟防火牆,修改生效
        service iptables restart    
 
 


免責聲明!

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



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