Centos防火墻以及端口基礎(chǔ)操作

Centos7以下

查看防火墻狀態(tài):serviceiptables status

開(kāi)啟防火墻(重啟后永久生效):chkconfig iptables on

關(guān)閉防火墻(重啟后永久生效):chkconfig iptables off

開(kāi)啟防火墻(即時(shí)生效,重啟后失效):service iptables start

關(guān)閉防火墻(即時(shí)生效,重啟后失效):service iptables stop

重啟防火墻:serviceiptables restartd


查看開(kāi)啟的端口號(hào):service iptables status

開(kāi)啟某個(gè)端口號(hào)(如80端口號(hào),命令方式)

iptables -A INPUT -p tcp -m state --stateNEW -m tcp --dport 80 -j ACCEPT

保存開(kāi)啟的端口號(hào):service iptables save

重新啟動(dòng)防火墻: service iptables restart


通過(guò)修改配置文件開(kāi)啟端口號(hào)(如80端口號(hào))

vi /etc/sysconfig/iptables
-A INPUT -p tcp -m state --state NEW -m tcp--dport 80 -j ACCEPT

啟動(dòng)防火墻:service iptables restart

CentOS 7以上

安裝firewall插件:yum install firewalld firewalld-config

配置文件:/etc/firewalld/

查看版本:firewall-cmd --version

查看幫助:firewall-cmd --help

查看區(qū)域信息:firewall-cmd --get-active-zones

查看指定接口所屬區(qū)域信息:firewall-cmd --get-zone-of-interface=eth0

拒絕所有包:firewall-cmd --panic-on

取消拒絕狀態(tài):firewall-cmd --panic-off

查看是否拒絕:firewall-cmd --query-panic

查看防火墻狀態(tài):firewall-cmd --state

開(kāi)啟防火墻:systemctl start firewalld

關(guān)閉防火墻:systemctl stop firewalld

設(shè)置開(kāi)機(jī)啟動(dòng):systemctl enable firewalld

停止并禁用開(kāi)機(jī)啟動(dòng): sytemctl disable firewalld

重啟防火墻:firewall-cmd --reload


查看指定區(qū)域所有開(kāi)啟的端口號(hào)

firewall-cmd --zone=public --list-ports

在指定區(qū)域開(kāi)啟端口(如80端口號(hào),命令方式)

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

重新啟動(dòng)防火墻:firewall-cmd --reload

參數(shù)說(shuō)明
: –zone 作用域
: –add-port=8080/tcp 添加端口,格式為:端口/通訊協(xié)議
: –permanent #永久生效,沒(méi)有此參數(shù)重啟后失效

在指定區(qū)域開(kāi)啟某個(gè)范圍的端口號(hào)(如18881~65534,命令方式)

firewall-cmd --zone=public--add-port=18881:65534/tcp --permanent

重新啟動(dòng)防火墻 firewall-cmd--reload

?著作權(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)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

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

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