云服务器免费试用

Centos7防火墙基本操作:开启/关闭/重启防火墙

技术文档 0 1493

centos7防火墙如何操作?centos7防火墙么查看状态,以及开启、关闭、重启防火墙乖行。firewall-cmd 是 firewalld 的主要命令行工具。它可用于获取有关 firewalld 的状态信息,获取运行时和永久环境的防火墙配置以及更改这些配置。

Centos7防火墙基本操作:开启/关闭/重启防火墙

一、查看防火墙

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

[root@localhost student]# firewall-cmd --state[root@localhost student]# systemctl status firewalld

2.查看防火墙是否开机自启。

[root@localhost student]# systemctl is-enabled

3.查看接口区域,这里以ens33为例。

[root@localhost student]# firewall-cmd --get-zone-of-interface=ens33public

4.查看绑定区域的接口。

[root@localhost student]# firewall-cmd --get-active-zonesdocker  interfaces: docker0public  interfaces: ens33

5.查看所有开放端口。

root@zq-virtual-machine:/home/zq# netstat -aptn

二、开启/关闭/重启防火墙

2.1 开启防火墙

1.执行systemctl start firewalld.service命令开启防火墙,默认是开启的。

[root@localhost student]# systemctl start firewalld.service

2.2 关闭防火墙

1.执行systemctl stop firewalld.service命令关闭防火墙。

[root@localhost student]# systemctl stop firewalld.service

2.3 重启防火墙

1.执行systemctl restart firewalld.service命令重启防火墙。

[root@localhost student]# systemctl restart firewalld.service

2.4 开机自启防火墙

1.执行systemctl enable firewalld.service命令设置防火墙开机自启。

[root@localhost student]# systemctl enable firewalld.service

三、打开端口/服务

3.1 打开端口

临时打开端口

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

[root@localhost student]# firewall-cmd --zone=public --add-port=80/tcp

2.执行systemctl restart firewalld.service命令重启防火墙。

[root@localhost student]# systemctl restart firewalld.service

注意:当开放端口设置完成后必须要重启,否则不生效!!!

永久打开端口

1.执行firewall-cmd –permanent –zone=public –add-port=80/tcp命令永久打开80/tcp。

[root@localhost student]# firewall-cmd --permanent --zone=public --add-port=80/tcp

2.执行systemctl restart firewalld.service命令重启防火墙。

[root@localhost student]# systemctl restart firewalld.service

注意:当开放端口设置完成后必须要重启,否则不生效!!!

3.2 打开服务

临时打开服务

1.执行firewall-cmd –zone=public –add-service=http命令公共区域中临时打开服务HTTP。

[root@localhost student]# firewall-cmd --zone=public --add-service=http

永久打开服务

1.执行firewall-cmd –permanent –zone=public –add-service=http命令公共区域中临时打开服务HTTP。

 [root@localhost student]# firewall-cmd --permanent --zone=public --add-service=http 

声明:本文内容由网友自发贡献,本站不承担相应法律责任。对本内容有异议或投诉,请联系2913721942@qq.com核实处理,我们将尽快回复您,谢谢合作!
若转载请注明出处: Centos7防火墙基本操作:开启/关闭/重启防火墙
本文地址: https://solustack.com/56842.html

相关推荐:

网友留言:

我要评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。