CentOS 下 firewalld 配置操作详解
一、firewalld基本配置
1、firewalld的基本使用
systemctl start firewalld # 启动 firewalld 服务
systemctl status firewalld #查看firewalld启动状态
systemctl stop firewalld #停止firewalld服务
systemctl disable firewalld #禁止firewalld服务
2.配置firewalld-cmd
firewall-cmd –version #查看版本
firewall-cmd –help #查看帮助
firewall-cmd –state #显示状态
firewall-cmd –zone=public –list-ports #查看所有放开的端口
firewall-cmd –reload #重载防火墙,使配置生效
firewall-cmd –get-active-zones #查看zone信息
firewall-cmd –get-zone-of-interface=eth0 #查看指定接口所属区域
firewall-cmd –panic-on #拒绝所有包
firewall-cmd –panic-off #取消拒绝状态
firewall-cmd –query-panic #查看是否拒绝
firewall-cmd –list-all #查看默认域下所有规则
firewall-cmd –list-rich-rules #查看所有富规则
firewall-cmd –zone=public –add-port=80/tcp –permanent (–permanent永久生效,没有此参数重启后失效) #放通80端口
firewall-cmd –permanent –zone=public –add-port=5901-5910/tcp –permanent #放通连续端口
firewall-cmd –permanent –zone=public –add-port=9000/tcp –add-port=9001/tcp #放通不连续端口
firewall-cmd –permanent –zone=public –add-service=ssh #放通SSH服务
firewall-cmd –permanent –zone=public –add-rich-rule="rule family="ipv4" source address="172.16.100.254/32" port protocol="tcp" port="4505" accept" #放通源IP地址及端口
firewall-cmd –permanent –remove-rich-rule="rule family="ipv4" source address="172.16.100.254/32" port port="4505" protocol="tcp" accept" #取消源IP地址及端口放行
firewall-cmd –zone= public –remove-port=80/tcp –permanent 删除端口放通
firewall-cmd –reload #重载防火墙,使配置生效
firewall-cmd –permanent –zone=public –list-services #查看所有放通的服务
firewall-cmd –permanent –zone=public –list-ports #查看所有放通的端口
firewall-cmd –zone= public –query-port=80/tcp #查看端口是否放通
二、ipset集合配置方法:
配置逻辑说明:
1)手动创建ipset配置文件
2)根据模板配置规则地址
3)将ipset应用到策略中
4)新增、删除IP地址规则
1、手动创建ipset配置文件
注意:集合命名规范:permit_端口_input
系统默认没有ipset配置文件,需要手动创建ipset配置文件
mkdir -p /etc/firewalld/ipsets/permit_22_input.xml permit_22_input就是ipset名称
<?xml version="1.0" encoding="utf-8"?>
<ipset type="hash:net">
<short>white-list</short>
<entry>192.168.1.1</entry>
<entry>192.168.1.2</entry>
</ipset>
2、将ipset应用到策略中
firewall-cmd –permanent –add-rich-rule \’rule family="ipv4" source ipset="permit_22_input" port port=22 protocol=tcp accept\’
firewall-c71f0md –reload
3、新增,删除IP地址
firewall-cmd –permanent –ipset=permit_22_input –add-entry="192.168.1.190"
firewall-cmd –permanent –ipset=permit_22_input –remove-entry="192.168.1.190"
firewall-cmd –reload
注:此方法新增,删除是ipset配置文件配置项
firewall-cmd –permanent –ipset=permit_22_input –get-entries #查看ipset集合中的地址
4、清除或删除ipset
firewall-cmd –permanent –delete-ipset=permit_22_input #清除ipset的xml配置文件信息
ipset destroy permit_22_input #清除ipset list信息
5、查看ipset信息
firewall-cmd –get-ipsets #查看ipset名称
firewall-cmd –info-ipset permit_22_input #查看ipset详细信息