當(dāng)前位置 主頁 > 技術(shù)大全 >
centos7防火墻如何操作?centos7防火墻么查看狀態(tài),以及開啟、關(guān)閉、重啟防火墻乖行。firewall-cmd 是 firewalld 的主要命令行工具。它可用于獲取有關(guān) firewalld 的狀態(tài)信息,獲取運(yùn)行時(shí)和環(huán)境的防火墻配置以及更改這些配置。
一、查看防火墻
1.查看防火墻此時(shí)運(yùn)行狀態(tài)。方式有兩種具體如下:
[root@localhost student]# firewall-cmd --state [root@localhost student]# systemctl status firewalld
2.查看防火墻是否開機(jī)自啟。
[root@localhost student]# systemctl is-enabled
3.查看接口區(qū)域,這里以ens33為例。
[root@localhost student]# firewall-cmd --get-zone-of-interface=ens33 public
4.查看綁定區(qū)域的接口。
[root@localhost student]# firewall-cmd --get-active-zones docker interfaces: docker0 public interfaces: ens33
5.查看所有開放端口。
root@zq-virtual-machine:/home/zq# netstat -aptn
二、開啟/關(guān)閉/重啟防火墻
2.1 開啟防火墻
1.執(zhí)行systemctl start firewalld.service命令開啟防火墻,默認(rèn)是開啟的。
[root@localhost student]# systemctl start firewalld.service
2.2 關(guān)閉防火墻
1.執(zhí)行systemctl stop firewalld.service命令關(guān)閉防火墻。
[root@localhost student]# systemctl stop firewalld.service
2.3 重啟防火墻
1.執(zhí)行systemctl restart firewalld.service命令重啟防火墻。
[root@localhost student]# systemctl restart firewalld.service
2.4 開機(jī)自啟防火墻
1.執(zhí)行systemctl enable firewalld.service命令設(shè)置防火墻開機(jī)自啟。
[root@localhost student]# systemctl enable firewalld.service
三、打開端口/服務(wù)
3.1 打開端口
臨時(shí)打開端口
1.執(zhí)行firewall-cmd –zone=public –add-port=80/tcp命令打開80/tcp。這里需要注意,這是臨時(shí)的打開端口,重啟后無效。
[root@localhost student]# firewall-cmd --zone=public --add-port=80/tcp
2.執(zhí)行systemctl restart firewalld.service命令重啟防火墻。
[root@localhost student]# systemctl restart firewalld.service
注意:當(dāng)開放端口設(shè)置完成后必須要重啟,否則不生效!!!
打開端口
1.執(zhí)行firewall-cmd –permanent –zone=public –add-port=80/tcp命令打開80/tcp。
[root@localhost student]# firewall-cmd --permanent --zone=public --add-port=80/tcp
2.執(zhí)行systemctl restart firewalld.service命令重啟防火墻。
[root@localhost student]# systemctl restart firewalld.service
注意:當(dāng)開放端口設(shè)置完成后必須要重啟,否則不生效!!!