软件下载

linux防火墙配置(Linux防火墙常用规则配置)

软件下载 投稿 2022-08-23 16:34:26 浏览

当使用firewalld-cmd添加防火墙规则时,它实际上是将配置转换成iptables规则后,再应用到系统中。

设有如下网络拓扑:

内网internal (172.12.0.100)
br1--Linux---br0---external(10.10.11.250)

1. 查询系统中的zone信息

 firewall-cmd  --get-zones
block dmz drop external home internal public trusted work

zone:它是安全域的范围,就类似于Window上的域网络,工作网络,家庭网络,Internet网络等,不同的安全作用域其安全级别不同,安全程度不同,家庭zone的安全规则就是最宽松的。

  • trusted(信任) ---可接受所有的网络连
  • home(家庭) ---- 用于家庭网路,默认仅接受ssh, mdns, ipp-client,dhcpv6-client服务连
  • internal(内部) --- 用于内部网络,默认仅接受ssh, mdns, ipp-client,dhcpv6-client服务连
  • work(工作) -- 用于工作区域,默认仅接受ssh, dhcpv6-client服务连
  • public(公共) --- 在公共区域使用,默认仅接受ssh,dhcpv6-client服务连,为firewalld的默认区域
  • external(外部) -- 出去的IPv4网络连,通过此区域或伪装(source nat)或是转发,仅接受ssh服务连接
  • dmz(非军事区) --- 仅接受ssh服务连
  • block(限制) ---拒绝所有的网络连接
  • drop(丢弃) ---任何接收的网络数据包都被丢弃,没有任何回复

 

2. 查询防火墙状态和配置信息

Firewall运行状态

[root@localhost ~]# firewall-cmd --state
Running

Firewall接口分配信息

[root@localhost ~]# firewall-cmd --list-all
public (active)
  target: default
  icmp-block-inversion: no
  interfaces: eth0 ens4
….

开放端口信息

[root@localhost ~]# firewall-cmd --list-port
500/udp 4500/udp

 

3. 更改接口所属区域

当前接口所属区域

firewall-cmd  --get-active-zones
public
  interfaces: eth0 ens4

更改接口区域

firewall-cmd --permanent --zone=external --change-interface=eth0
firewall-cmd --permanent --zone=internal --change-interface=ens4

 

更改后的区域归属

firewall-cmd  --get-active-zones
internal
  interfaces: ens4
external
  interfaces: eth0

 

4. 区域中添加、删除接口

将接口加入到区域中

firewall-cmd --permanent --zone=internal --add-interface=eth0

将接口从区域中删除

firewall-cmd --permanent --zone=internal --remove-interface=eth0

参数permanent指的是配置将永久有效

 

5. 添加、删除服务或端口

在公共区域添加邮件服务

firewall-cmd --permanent --zone=public --add-service=smtp

在公共区域删除邮件服务

firewall-cmd --permanent --zone=public --remove-service=smtp

在所有区域添加、删除udp端口67

firewall-cmd –permanent –add-port=67/udp
firewall-cmd –permanent -remove-port=67/udp

 

6. 设置、删除网络地址到指定的区域

firewall-cmd --permanent --zone=internal --add-source=172.12.0.0/24

firewall-cmd --permanent --zone=internal --remove-source=172.12.0.0/24

 

7. 添加、删除DNAT转发

在本机所有端口上接收到TCP 4522的报文时,将报文的目的地址和端口转换为内部网络的172.12.0.11:22端口

firewall-cmd --add-forward-port=port=4522:proto=tcp:toport=22:toaddr=172.12.0.11 –permanent

删除DNAT规则

firewall-cmd --remove-forward-port=port=4522:proto=tcp:toport=22:toaddr=172.12.0.11 --permanent

添加DNAT规则到区域

firewall-cmd --zone=internal --add-forward-port=port=4522:proto=tcp:toport=22:toaddr=172.12.0.11 –permanent

从区域中删除DNAT规则

firewall-cmd --zone=internal --remove-forward-port=port=4522:proto=tcp:toport=22:toaddr=172.12.0.11 –permanent

 

8. SNAT规则添加、删除

设置IP地址伪装(SNAT)

firewall-cmd --zone=external --add-masquerade –permanent

删除SNAT规则

firewall-cmd --zone=external --remove-masquerade –permanent

将source为192.168.2.0网段来的数据包伪装成external(即ens4)的地址

firewall-cmd --permanent --zone=external --add-rich-rule=‘rule family=ipv4 source address=192.168.2.0/24 masquerade’

将source为192.168.2.0网段来的数据包伪装成external(即ens4)地址的规则移除

firewall-cmd --permanent --zone=external --remove-rich-rule=‘rule family=ipv4 source address=192.168.2.0/24 masquerade’

9. 查询端口是否打开

firewall-cmd    --query-port=80/tcp

 

10. 重载Firewall使配置生效

firewall-cmd --reload

「真诚赞赏,手留余香」

求资源网

真诚赞赏,手留余香

使用微信扫描二维码完成支付

继续浏览有关编程的文章
发表评论
留言与评论(共有 0 条评论)
   
验证码:
版权声明

求资源网所发布的一切破解补丁,软件,以及其他分析文章仅限用于学习和研究目的;不得将上述内容用于商业或者非法用途。
否则,一切后果请用户自负。本站信息来自网络,版权争议与本站无关。您必须在下载后的24个小时之内,从您的电脑中彻底删除上述内容。如果您喜欢该程序,请支持正版软件,购买注册,得到更好的正版服务。如有侵权请邮件与我们联系处理。