CentOS 6和CentOS 7防火牆的關閉,6和centos

來源:互聯網
上載者:User

CentOS 6和CentOS 7防火牆的關閉,6和centos

CentOS6.5查看防火牆的狀態:

1 [linuxidc@localhost ~]$service iptable status

  顯示結果:

1 2 3 4 5 [linuxidc@localhost ~]$service iptable status Redirecting to /bin/systemctl status iptable.service ● iptable.service Loaded: not-found (Reason: No such file or directory) Active: inactive (dead) --表示防火牆已經關閉

CentOS 6.5關閉防火牆

1 2 [root@localhost ~]#servcie iptables stop --臨時關閉防火牆 [root@localhost ~]#chkconfig iptables off --永久關閉防火牆

CentOS 7.2關閉防火牆

CentOS 7.0預設使用的是firewall作為防火牆,這裡改為iptables防火牆步驟。


firewall-cmd --state #查看預設防火牆狀態(關閉後顯示notrunning,開啟後顯示running)

1 2 [root@localhost ~]#firewall-cmd --state not running

檢查防火牆的狀態:

從centos7開始使用systemctl來管理服務和程式,包括了service和chkconfig。

1 2 [root@localhost ~]#systemctl list-unit-files|grep firewalld.service --防火牆處於關閉狀態 firewalld.service disabled

  或者

1 2 3 4 [root@localhost ~]#systemctl status firewalld.service ● firewalld.service - firewalld - dynamic firewall daemon Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled) Active: inactive (dead)

關閉防火牆:

systemctl stop firewalld.service #停止firewall
systemctl disable firewalld.service #禁止firewall開機啟動

1 2 [root@localhost ~]#systemctl stop firewalld.service [root@localhost ~]#systemctl disable firewalld.service
1 2 3 4 5 6 7 8 啟動一個服務: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;echo $? 查看已啟動的服務列表:systemctl list-unit-files|grep enabled
Centos 7 firewall 命令:

查看已經開放的連接埠:

firewall-cmd --list-ports

開啟連接埠

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

命令含義:

–zone #範圍

–add-port=80/tcp #添加連接埠,格式為:連接埠/通訊協議

–permanent #永久生效,沒有此參數重啟後失效

重啟防火牆

firewall-cmd --reload #重啟firewallsystemctl stop firewalld.service #停止firewallsystemctl disable firewalld.service #禁止firewall開機啟動firewall-cmd --state #查看預設防火牆狀態(關閉後顯示notrunning,開啟後顯示running)
CentOS 7 以下版本 iptables 命令

如要開放80,22,8080 連接埠,輸入以下命令即可

/sbin/iptables -I INPUT -p tcp --dport 80 -j ACCEPT/sbin/iptables -I INPUT -p tcp --dport 22 -j ACCEPT/sbin/iptables -I INPUT -p tcp --dport 8080 -j ACCEPT

然後儲存:

/etc/rc.d/init.d/iptables save

查看開啟的連接埠:

/etc/init.d/iptables status

關閉防火牆
1) 永久性生效,重啟後不會複原

開啟: chkconfig iptables on

關閉: chkconfig iptables off

2) 即時生效,重啟後複原

開啟: service iptables start

關閉: service iptables stop

查看防火牆狀態: service iptables status

下面說下CentOS7和6的預設防火牆的區別

CentOS 7預設使用的是firewall作為防火牆,使用iptables必須重新設定一下

1、直接關閉防火牆

systemctl stop firewalld.service #停止firewall

systemctl disable firewalld.service #禁止firewall開機啟動

2、設定 iptables service

yum -y install iptables-services

如果要修改防火牆配置,如增加防火牆連接埠3306

vi /etc/sysconfig/iptables

增加規則

-A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT

儲存退出後

systemctl restart iptables.service #重啟防火牆使配置生效

systemctl enable iptables.service #設定防火牆開機啟動

最後重啟系統使設定生效即可。

systemctl start iptables.service #開啟防火牆

systemctl stop iptables.service #關閉防火牆

解決主機不能訪問虛擬機器CentOS中的網站前陣子在虛擬機器上裝好了CentOS6.2,並配好了apache+php+mysql,但是本機就是無法訪問。一直就沒去折騰了。 具體情況如下 1. 本機能ping通虛擬機器 2. 虛擬機器也能ping通本機 3.虛擬機器能訪問自己的web 4.本機無法訪問虛擬機器的web 後來發現是 防火牆將80連接埠屏蔽了的緣故。 檢查是不是伺服器的80連接埠被防火牆堵了,可以通過命令:telnet server_ip 80 來測試。 解決方案如下: /sbin/iptables -I INPUT -p tcp --dport 80 -j ACCEPT 然後儲存: /etc/rc.d/init.d/iptables save 重啟防火牆 /etc/init.d/iptables restart CentOS防火牆的關閉,關閉其服務即可: 查看CentOS防火牆資訊:/etc/init.d/iptables status 關閉CentOS防火牆服務:/etc/init.d/iptables stop

更多CentOS相關資訊見CentOS 專題頁面 http://www.linuxidc.com/topicnews.aspx?tid=14

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.