【CentOS】防火墙firewalld

CentOS7 采用firewalld做为防火墙,以前是采用iptables做为防火墙。 服务器没法链接多是防火墙限制的缘由。
修改防火墙配置。修改完后须要重启生效:firewall-cmd --reload
 

一、直接修改配置文件:/etc/firewalld/zones/public.xml(白名单模式)

<?xml version="1.0" encoding="utf-8"?>
<zone>
<short>Public</short>
<description>For use in public areas. 
You do not trust the other computers on networks to not harm your computer. 
Only selected incoming connections are accepted.</description>
<servicename="dhcpv6-client"/>
<servicename="http"/> <!--容许http协议 -->
<servicename="ssh"/> <!--容许ssh协议 -->
<servicename="https"/> <!--容许https协议 -->
</zone>

二、经过命令修改配置

##Add
firewall-cmd --permanent --zone=public--add-port=80/tcp
##Remove
firewall-cmd --permanent --zone=public--remove-port=80/tcp
##Reload
firewall-cmd --reload

三、经常使用命令

查看防火墙状态:systemctl status firewalld.service
启动防火墙:systemctl start firewalld.service
关闭防火墙:systemctl stop firewalld.service
从新启动防火墙:systemctl restart firewalld.service