Firewalld防火墙

今天给大家分享一些firewalld防火墙常见的维护命令

  • 查看防火墙状态

systemctl status firewalld
  • 关闭防火墙

systemctl stop firewalld
  • 开启防火墙

systemctl start firewalld
  • 永久开启防火墙

systemctl enable firewalld
  • 永久关闭防火墙

systemctl disable firewalld
  • 重载防火墙规则

firewall-cmd --reload
  • 查看防火墙状态

firewall-cmd --state 
  • 查看版本

firewall-cmd --version
  • 查看帮助

firewall-cmd --help
  • 查看所有配置信息

# --zone可以指定区域,不指定为默认的区域
firewall-cmd --list-all --zone=work
  • 查看所有开放的端口

# --zone可以指定区域,不指定为默认的区域
firewall-cmd --list-ports --zone=work
  • 查看所有允许的服务

# --zone可以指定区域,不指定为默认的区域
firewall-cmd --list-services --zone=work
  • 获取所有支持的服务

firewall-cmd --get-services
  • 拒绝所有包

firewall-cmd --panic-on
  • 取消拒绝状态

firewall-cmd --panic-off
  • 查看是否拒绝

firewall-cmd --query-panic
  • 禁用传统防火墙服务

systemctl mask iptables
systemctl mask ip6tables
systemctl mask ebtables
  • 将网络接口关联至drop区域

# 使用--permanent表示永久生效,需要使用--reload才行
firewall-cmd --permanent --change-interface=eth0 --zone=drop
firewall-cmd --reload
  • 添加网段白名单

# 对192.168.47网段生效
firewall-cmd --permanent --add-source=192.168.47.0/24 --zone=trusted
# 对192.168.47.101地址生效
firewall-cmd --permanent --add-source=192.168.47.101/32 --zone=trusted
firewall-cmd --reload
  • 开放指定端口

firewall-cmd --zone=public --add-port=80/tcp --permanent
firewall-cmd --reload
  • 添加多个端口

firewall-cmd --permanent --zone=public --add-port=8080-8083/tcp
  • 移除开放的端口

firewall-cmd --zone=public --remove-port=80/tcp --permanent
firewall-cmd --reload
  • 允许访问http,https服务

firewall-cmd --permanent --add-service=http --add-service=https 
firewall-cmd --reload
  • 移除开放访问的服务

firewall-cmd --permanent --remove-service=http 
firewall-cmd --reload
  • 流量转发命令

firewall-cmd  --permanent --zone=<区域> --add-forward-port=port=<源端口>:proto=<协议>:toport=<目的端口>:toaddr=<目的地址>
​
# 将本机2222/tcp端口转发至192.168.47.111:22端口
# 开启IP伪装
firewall-cmd --permanent --add-masquerade
​
# 配置端口转发规则
firewall-cmd  --permanent --zone=public --add-forward-port=port=2222:proto=tcp:toport=22:toaddr=192.168.47.111
​
firewall-cmd --reload
  • 删除端口转发规则

firewall-cmd  --permanent --zone=public --remove-forward-port=port=2222:proto=tcp:toport=22:toaddr=192.168.47.111
  • 仅允许192.168.47.111访问8080端口

firewall-cmd --permanent --add-rich-rule='rule family=ipv4 source address=192.168.47.111/32 port port=8080 protocol=tcp accept'
  • 将192.168.47.111加入白名单

firewall-cmd --permanent --add-rich-rule="rule family="ipv4" source address="192.168.47.111" accept" 
    
  • 删除配置的规则

firewall-cmd --permanent --remove-rich-rule='rule family="ipv4" source address="192.168.47.111/32" port port="8080" protocol="tcp" accept' 
firewall-cmd --permanent --remove-rich-rule="rule family="ipv4" source address="192.168.47.111" accept"
  • 拒绝192.168.47.111访问ssh服务

firewall-cmd --permanent --zone=public --add-rich-rule='rule family=ipv4 source address=192.168.47.111/32 service name=ssh drop'
  • 将远程192.168.47.1主机请求firewalld的3333端口转发至本机22端口

firewall-cmd --permanent --zone=public --add-rich-rule='rule family=ipv4 source address=192.168.207.1/24 forward-port port=81 protocol=tcp to-port=80'
  • 获取所有支持的ICMP类型

firewall-cmd --get-icmptypes
  • 启用区域的 ICMP 阻塞功能

# 不加zone表示默认的区域
firewall-cmd [--zone=<zone>] --add-icmp-block=<icmptype>
firewall-cmd --add-icmp-block=echo-request
  • 禁止区域的 ICMP 阻塞功能

firewall-cmd [--zone=<zone>] --remove-icmp-block=<icmptype>
  • 查询区域的 ICMP 阻塞功能

firewall-cmd [--zone=<zone>] --query-icmp-block=<icmptype>
  • firewalld富规则

firewall-cmd --add-rich-rule='rule family=ipv4 source address=192.168.207.0/24 accept'
firewall-cmd --add-rich-rule='rule family=ipv4 source address=192.168.207.0/24 reject'
firewall-cmd --add-rich-rule='rule family=ipv4 destination address=192.168.207.0/24 drop'
​
firewall-cmd --remove-rich-rule='rule family=ipv4 source address=192.168.207.0/24 accept'

  • 15
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值