詳解centos6和centos7防火墻的關(guān)閉
CentOS6.5查看防火墻的狀態(tài):
[zh@localhost ~]$service iptable status
顯示結(jié)果:
[zh@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) --表示防火墻已經(jīng)關(guān)閉
CentOS 6.5關(guān)閉防火墻
[root@localhost ~]#servcie iptables stop --臨時(shí)關(guān)閉防火墻 [root@localhost ~]#chkconfig iptables off --永久關(guān)閉防火墻
CentOS 7.2關(guān)閉防火墻
CentOS 7.0默認(rèn)使用的是firewall作為防火墻,這里改為iptables防火墻步驟。
firewall-cmd --state #查看默認(rèn)防火墻狀態(tài)(關(guān)閉后顯示notrunning,開啟后顯示running)
[root@localhost ~]#firewall-cmd --state not running
檢查防火墻的狀態(tài):
從centos7開始使用systemctl來管理服務(wù)和程序,包括了service和chkconfig。
[root@localhost ~]#systemctl list-unit-files|grep firewalld.service --防火墻處于關(guān)閉狀態(tài) firewalld.service disabled
或者
[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)
關(guān)閉防火墻:
systemctl stop firewalld.service #停止firewall
systemctl disable firewalld.service #禁止firewall開機(jī)啟動(dòng)
[root@localhost ~]#systemctl stop firewalld.service [root@localhost ~]#systemctl disable firewalld.service
啟動(dòng)一個(gè)服務(wù):systemctl start firewalld.service 關(guān)閉一個(gè)服務(wù):systemctl stop firewalld.service 重啟一個(gè)服務(wù):systemctl restart firewalld.service 顯示一個(gè)服務(wù)的狀態(tài):systemctl status firewalld.service 在開機(jī)時(shí)啟用一個(gè)服務(wù):systemctl enable firewalld.service 在開機(jī)時(shí)禁用一個(gè)服務(wù):systemctl disable firewalld.service 查看服務(wù)是否開機(jī)啟動(dòng):systemctl is-enabled firewalld.service;echo $? 查看已啟動(dòng)的服務(wù)列表:systemctl list-unit-files|grep enabled
Centos 7 firewall 命令:
查看已經(jīng)開放的端口:
firewall-cmd --list-ports
開啟端口
firewall-cmd --zone=public --add-port=80/tcp --permanent
命令含義:
–zone #作用域
–add-port=80/tcp #添加端口,格式為:端口/通訊協(xié)議
–permanent #永久生效,沒有此參數(shù)重啟后失效
重啟防火墻
firewall-cmd --reload #重啟firewall systemctl stop firewalld.service #停止firewall systemctl disable firewalld.service #禁止firewall開機(jī)啟動(dòng) firewall-cmd --state #查看默認(rèn)防火墻狀態(tài)(關(guān)閉后顯示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
關(guān)閉防火墻
1) 永久性生效,重啟后不會(huì)復(fù)原
開啟: chkconfig iptables on
關(guān)閉: chkconfig iptables off
2) 即時(shí)生效,重啟后復(fù)原
開啟: service iptables start
關(guān)閉: service iptables stop
查看防火墻狀態(tài): service iptables status
下面說下CentOS7和6的默認(rèn)防火墻的區(qū)別
CentOS 7默認(rèn)使用的是firewall作為防火墻,使用iptables必須重新設(shè)置一下
1、直接關(guān)閉防火墻
systemctl stop firewalld.service #停止firewall systemctl disable firewalld.service #禁止firewall開機(jī)啟動(dòng)
2、設(shè)置 iptables service
yum -y install iptables-services
如果要修改防火墻配置,如增加防火墻端口3306
vi /etc/sysconfig/iptables
增加規(guī)則
-A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT
保存退出后
systemctl restart iptables.service #重啟防火墻使配置生效 systemctl enable iptables.service #設(shè)置防火墻開機(jī)啟動(dòng)
最后重啟系統(tǒng)使設(shè)置生效即可。
systemctl start iptables.service #打開防火墻 systemctl stop iptables.service #關(guān)閉防火墻
解決主機(jī)不能訪問虛擬機(jī)CentOS中的站點(diǎn)
前陣子在虛擬機(jī)上裝好了CentOS6.2,并配好了apache+php+mysql,但是本機(jī)就是無法訪問。一直就沒去折騰了。
具體情況如下
1. 本機(jī)能ping通虛擬機(jī)
2. 虛擬機(jī)也能ping通本機(jī)
3.虛擬機(jī)能訪問自己的web
4.本機(jī)無法訪問虛擬機(jī)的web
后來發(fā)現(xiàn)是防火墻將80端口屏蔽了的緣故。
檢查是不是服務(wù)器的80端口被防火墻堵了,可以通過命令:telnet server_ip 80 來測(cè)試。
解決方法如下:
/sbin/iptables -I INPUT -p tcp --dport 80 -j ACCEPT
然后保存:
/etc/rc.d/init.d/iptables save
重啟防火墻
/etc/init.d/iptables restart
CentOS防火墻的關(guān)閉,關(guān)閉其服務(wù)即可:
查看CentOS防火墻信息:/etc/init.d/iptables status
關(guān)閉CentOS防火墻服務(wù):/etc/init.d/iptables stop
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
Yum中報(bào)錯(cuò):“pycurl.so: undefined symbol: CRYPTO_num_locks”的問題排查
這篇文章主要給大家介紹了在Yum中報(bào)錯(cuò): "pycurl.so: undefined symbol: CRYPTO_num_locks"的問題排查的相關(guān)資料,文中通過圖文介紹的非常詳細(xì),需要的朋友可以參考借鑒,下面來一起看看吧。2017-06-06Linux安裝NodeJs并配合Nginx實(shí)現(xiàn)反向代理
本篇文章主要介紹了Linux安裝NodeJs并配合Nginx實(shí)現(xiàn)反向代理,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下。2016-11-11linux?系統(tǒng)進(jìn)程管理工具systemd詳解(systemctl命令、創(chuàng)建自己的systemd服務(wù))
Unit?是?Systemd?管理系統(tǒng)資源的基本單元,可以認(rèn)為每個(gè)系統(tǒng)資源就是一個(gè)?Unit,并使用一個(gè)?Unit?文件定義,這篇文章主要介紹了linux?系統(tǒng)進(jìn)程管理工具systemd詳解(systemctl命令、創(chuàng)建自己的systemd服務(wù)),需要的朋友可以參考下2022-12-12linux下使用cmake編譯安裝mysql的詳細(xì)教程
這篇文章主要介紹了linux下使用cmake編譯安裝mysql的詳細(xì)教程,非常不錯(cuò),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2019-10-10Linux關(guān)機(jī)時(shí)執(zhí)行指定腳本功能實(shí)現(xiàn)
本篇文章給大家分享了Linux關(guān)機(jī)時(shí)執(zhí)行指定腳本功能的實(shí)現(xiàn)詳解,對(duì)此有需要的朋友跟著小編一起學(xué)習(xí)下。2018-03-03