java后端集群化专题

centos7防火墙firewalld

2018-04-01  本文已影响95人  江江的大猪

版权声明:本文为原创内容,转载请声明出处。
原文地址:http://www.excelib.com/article/288/show

firewalld简介

  1. Centos7中默认将原来的防火墙iptables升级为了firewalld
  2. firewalld可以动态修改单条规则,而不需要像iptables那样,在修改了规则后必须得全部刷新才可以生效

firewalld和iptables的关系

firewalld的配置模式

配置文件结构

zone

<?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>
  <service name="ssh"/>
  <service name="dhcpv6-client"/>
</zone>
<?xml version="1.0" encoding="utf-8"?>
<zone target="ACCEPT">
  <short>Trusted</short>
  <description>All network connections are accepted.</description>
</zone>

service

<?xml version="1.0" encoding="utf-8"?>
<service>
  <short>SSH</short>
  <description>Secure Shell (SSH) is a protocol for logging into and executing commands on remote machines. It provides secure encrypted communications. If you plan on accessing your machine remotely via SSH over a firewalled interface, enable this option. You need the openssh-server package installed for this option to be useful.</description>
  <port protocol="tcp" port="22"/>
</service>

配置方法

启动停止和查询状态

# 启动
[root@excelib.com ~]# systemctl start firewalld
# 停止
[root@excelib.com ~]# systemctl stop firewalld
# 重启
[root@excelib.com ~]# systemctl restart firewalld
# 查询状态
[root@excelib.com ~]$ systemctl status firewalld
# 另外,对于firewalld来说还可以使用自身的firewall-cmd工具来查询运行状态
[root@excelib.com ~]$ firewall-cmd --state
# 启用开机自动启动
[root@excelib.com ~]$ systemctl enable firewalld
# 禁用开机自动启动
[root@excelib.com ~]$ systemctl disable firewalld
# 查看自动启动状态
[root@excelib.com ~]$ systemctl is-enabled firewalld

更新规则

[root@excelib.com ~]# firewall-cmd --reload
[root@excelib.com ~]# firewall-cmd --complete-reload

策略操作

# --query-xxx主要用于布尔值的查询,比如
[root@excelib.com ~]$ firewall-cmd --zone=public --query-service=ssh
这个命令用于查询在public这个zone中是否包含ssh这个服务。
# --get-xxx主要用于获取特定的内容,比如
[root@excelib.com ~]$ firewall-cmd --get-zones
# 这样就可以获取到预设的zones,默认情况下返回结果为
block dmz drop external home internal public trusted work
# --list-xxx主要用于按一定条件进行查询(不过有的list命名也不需要条件),比如
[root@excelib.com ~]$ firewall-cmd --zone=public --list-services
上一篇 下一篇

猜你喜欢

热点阅读