CentOS7命令

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

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容