firewalld详解

匿名 (未验证) 提交于 2019-12-03 00:40:02

https://blog.csdn.net/gg_18826075157/article/details/72834694


大致用法就是:把可信任的IP地址添加到“trusted”区域,把不可信任的IP地址添加到“block”区域,把要公开的网络服务添加到“public”区域。

firewalld的配置文件一般存放在下面两个目录:

  1. /etc/firewalld/
  2. /usr/lib/firewalld/

当需要一个文件时firewalld会优先使用第一个目录的。


这两个配置目录的结构很简单,主要是两个文件和三个目录:



      • ①DefaultZone:默认使用的zone;
      • ②MinimalMark:使用标记的最小值;
      • ③CleanuupOnExit:退出后是否清除防火墙规则;
      • ④Lockdown:是否限制别的程序通过D-BUS接口直接操作firewalld;
      • ⑤IPv6_rpfilter:判断所接受到的包是否是伪造的
    • lockdown-whitelist.xml:当Lockdown设置为yes时,规定哪些程序可以对firewalld进行操作
    • direct.xml:直接使用类似iptables的语法来进行规则的增删

    • zones:保存zone配置文件
    • services:保存service配置文件
    • icmptypes:保存和icmp类型相关的配置文件

所谓的区域就是一个信赖等级,某一等级下对应有一套规则集。划分方法包括:网络接口、IP地址、端口号等等。一般情况下,会有如下的这些默认区域:

  1. drop:丢弃所有进入的数据包
  2. block:拒绝所有进入的数据包
  3. public:只接受部分选定的数据包
  4. external:应用在NAT设定时的对外网络
  5. dmz:非军事区
  6. work:使用在公司环境
  7. home:使用在家庭环境
  8. internal:应用在NAT设定时的对内网络
  9. trusted:接受所有的数据包

比如,public区域由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>   <service name="ssh"/>   <service name="dhcpv6-client"/> </zone>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

当然,你也可以定义自己的区域,只要在zones目录下新建一个同名的xml文件即可。

iptables时代习惯使用端口号来匹配规则,但是如果某一个服务的端口号改变了,那就要同时更改iptables的规则,十分不方便,同时也不方便阅读理解。

service配置文件的命名为<服务名>.xml,比如ssh的配置文件是ssh.xml。

 <?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>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

# systemctl enable firewalld # systemctl start firewalld
  • 1
  • 2

# firewall-cmd --zone=trusted --add-source=xxx.xxx.xxx.xxx
  • 1

# firewall-cmd --zone=public --add-interface=eth0
  • 1

# firewall-cmd --zone=public --add-service=http # firewall-cmd --zone=public --add-service=https
  • 1
  • 2

# firewall-cmd --zone=public --remove-service=dhcpv6-client # firewall-cmd --zone=public --remove-service=ssh
  • 1
  • 2

# firewall-cmd --get-active-zones public   interfaces: eth0 trusted   sources: xxx.xxx.xxx.xxx
  • 1
  • 2
  • 3
  • 4
  • 5

# firewall-cmd --zone=public --list-services # firewall-cmd --zone=trusted --list-services
  • 1
  • 2
CentOS7防火墙firewalld简单配置和使用

网上找了好多文章,关于CentOS7的防火墙配置和使用,都没有比较理想的说明firewalld的用法,还有一些网上摒弃centos7 firewalld防火墙,使用旧版本的iptables的替代的做法,这里笔者非常不赞同其再使用iptables。

新版的Kernel内核已经有了防火墙netfilter,并且firewalld的使用效能更高,稳定性更好

CentOS7配置防火墙的两种方法:

方法一
cp /usr/lib/firewalld/services/http.xml /etc/firewalld/services/
firewall-cmd --reload

、使用命令的方式配置;

方法二
##Add
firewall-cmd --permanent --zone=public --add-port=80/tcp

##Remove
firewall-cmd --permanent --zone=public --remove-port=80/tcp

##Reload
firewall-cmd --reload

public.xml里面新增<service name="http"/>,否则http的防火墙规则不会生效,而且两种配置方式都需要重新载入防火墙。

https://blog.csdn.net/gg_18826075157/article/details/72834694


大致用法就是:把可信任的IP地址添加到“trusted”区域,把不可信任的IP地址添加到“block”区域,把要公开的网络服务添加到“public”区域。

firewalld的配置文件一般存放在下面两个目录:

  1. /etc/firewalld/
  2. /usr/lib/firewalld/

当需要一个文件时firewalld会优先使用第一个目录的。


这两个配置目录的结构很简单,主要是两个文件和三个目录:



      • ①DefaultZone:默认使用的zone;
      • ②MinimalMark:使用标记的最小值;
      • ③CleanuupOnExit:退出后是否清除防火墙规则;
      • ④Lockdown:是否限制别的程序通过D-BUS接口直接操作firewalld;
      • ⑤IPv6_rpfilter:判断所接受到的包是否是伪造的
    • lockdown-whitelist.xml:当Lockdown设置为yes时,规定哪些程序可以对firewalld进行操作
    • direct.xml:直接使用类似iptables的语法来进行规则的增删

    • zones:保存zone配置文件
    • services:保存service配置文件
    • icmptypes:保存和icmp类型相关的配置文件

所谓的区域就是一个信赖等级,某一等级下对应有一套规则集。划分方法包括:网络接口、IP地址、端口号等等。一般情况下,会有如下的这些默认区域:

  1. drop:丢弃所有进入的数据包
  2. block:拒绝所有进入的数据包
  3. public:只接受部分选定的数据包
  4. external:应用在NAT设定时的对外网络
  5. dmz:非军事区
  6. work:使用在公司环境
  7. home:使用在家庭环境
  8. internal:应用在NAT设定时的对内网络
  9. trusted:接受所有的数据包

比如,public区域由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>   <service name="ssh"/>   <service name="dhcpv6-client"/> </zone>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

当然,你也可以定义自己的区域,只要在zones目录下新建一个同名的xml文件即可。

iptables时代习惯使用端口号来匹配规则,但是如果某一个服务的端口号改变了,那就要同时更改iptables的规则,十分不方便,同时也不方便阅读理解。

service配置文件的命名为<服务名>.xml,比如ssh的配置文件是ssh.xml。

 <?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>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

# systemctl enable firewalld # systemctl start firewalld
  • 1
  • 2

# firewall-cmd --zone=trusted --add-source=xxx.xxx.xxx.xxx
  • 1

# firewall-cmd --zone=public --add-interface=eth0
  • 1

# firewall-cmd --zone=public --add-service=http # firewall-cmd --zone=public --add-service=https
  • 1
  • 2

# firewall-cmd --zone=public --remove-service=dhcpv6-client # firewall-cmd --zone=public --remove-service=ssh
  • 1
  • 2

# firewall-cmd --get-active-zones public   interfaces: eth0 trusted   sources: xxx.xxx.xxx.xxx
  • 1
  • 2
  • 3
  • 4
  • 5

# firewall-cmd --zone=public --list-services # firewall-cmd --zone=trusted --list-services
  • 1
  • 2
文章来源: firewalld详解
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!