上一篇 下一篇 分享链接 返回 返回顶部

香港VPS的Centos7防火墙基本操作:开启/关闭/重启防火墙

发布人:欢子 发布时间:2026-01-21 15:11 阅读量:9
VPS和服务器中的centos7系统防火墙如何操作?centos7防火墙么查看状态,以及开启、关闭、重启防火墙乖行。firewall-cmd是firewalld的主要命令行工具。它可用于获取有关firewalld的状态信息,获取运行时和永久环境的防火墙配置以及更改这些配置。

一、查看防火墙1.查看防火墙此时运行状态。方式有两种具体如下:

[root@localhoststudent]#firewall-cmd--state[root@localhoststudent]#systemctlstatusfirewalld2.查看防火墙是否开机自启。

[root@localhoststudent]#systemctlis-enabled3.查看接口区域,这里以ens33为例。

[root@localhoststudent]#firewall-cmd--get-zone-of-interface=ens33public4.查看绑定区域的接口。

[root@localhoststudent]#firewall-cmd--get-active-zonesdockerinterfaces:docker0publicinterfaces:ens335.查看所有开放端口。

root@zq-virtual-machine:/home/zq#netstat-aptn二、开启/关闭/重启防火墙2.1开启防火墙1.执行systemctlstartfirewalld.service命令开启防火墙,默认是开启的。

[root@localhoststudent]#systemctlstartfirewalld.service2.2关闭防火墙1.执行systemctlstopfirewalld.service命令关闭防火墙。

[root@localhoststudent]#systemctlstopfirewalld.service2.3重启防火墙1.执行systemctlrestartfirewalld.service命令重启防火墙。

[root@localhoststudent]#systemctlrestartfirewalld.service2.4开机自启防火墙1.执行systemctlenablefirewalld.service命令设置防火墙开机自启。

[root@localhoststudent]#systemctlenablefirewalld.service三、打开端口/服务3.1打开端口临时打开端口

1.执行firewall-cmdCzone=publicCadd-port=80/tcp命令打开80/tcp。这里需要注意,这是临时的打开端口,重启后无效。

[root@localhoststudent]#firewall-cmd--zone=public--add-port=80/tcp2.执行systemctlrestartfirewalld.service命令重启防火墙。

[root@localhoststudent]#systemctlrestartfirewalld.service注意:当开放端口设置完成后必须要重启,否则不生效!!!

永久打开端口

1.执行firewall-cmdCpermanentCzone=publicCadd-port=80/tcp命令永久打开80/tcp。

[root@localhoststudent]#firewall-cmd--permanent--zone=public--add-port=80/tcp2.执行systemctlrestartfirewalld.service命令重启防火墙。

[root@localhoststudent]#systemctlrestartfirewalld.service注意:当开放端口设置完成后必须要重启,否则不生效!!!

3.2打开服务临时打开服务

1.执行firewall-cmdCzone=publicCadd-service=http命令公共区域中临时打开服务HTTP。

[root@localhoststudent]#firewall-cmd--zone=public--add-service=http永久打开服务

1.执行firewall-cmdCpermanentCzone=publicCadd-service=http命令公共区域中临时打开服务HTTP。

[root@localhoststudent]#firewall-cmd--permanent--zone=public--add-service=http
目录结构
全文