firewalld防火墙

firewalld-cmd(命令行模式)

firewall-cmd +下面内容

--state                # 显示firewalld的状态;
--reload               # 不中断服务的重新加载;
--complete-reload      # 中断所有连接的重新加载;
--runtime-to-permanent # 将当前防火墙的规则永久保存;
--check-config         # 检查配置正确性;

firewalld的规则分为两种状态

  1. runtime运行时: 修改规则马上生效,但是是临时生效 [不建议]
firewall-cmd --add-forward-port=port=80:proto=tcp:toport=8080
firewall-cmd --runtime-to-permanent         #没有这条命令重启计算机或重新加载后,上面的规则就不存在了
  1. permanent持久配置: 修改后需要reload重载才会生效 [强烈推荐]
firewall-cmd --permanent --zone=work --add-port=1000/tcp       #重启电脑后规则依然存在

九个区域(zone)

  1. public(公共区域):不相信网络上的人和计算机,不会损害你的计算机
  2. block(阻塞区域):人和传入的网络数据包都会将被阻止
  3. work(工作区域):相信网络上的其他计算机,不会损害你的计算机
  4. home(家庭区域):相信网络上的任何计算机,不会损害你的计算机
  5. DMZ(隔离区域):隔离区域也称为非军事区域,内外网络之间增加的一层网络,起到缓冲作用。对于隔离区域,只有选择接受传入的网络连接
  6. trusted(信任区域):所有网络连接都可以接受
  7. drop(丢弃区域):人和传入的网络连接都被拒绝
  8. intermal(内部区域):信任网络上的其他计算机,不会损害你的计算机。只有选择接受传入的网络连接
  9. external(外部区域):不相信网络上的其他计算机,不会损害你的计算机。只有选择接受传入的网络连接
    firewalld的默认区域是public

每个区域的列表

[root@localhost ~]# firewall-cmd --zone=public --list-all
public (active)
  target: default                              #i    该区域的状态(public默认区域)
  icmp-block-inversion: no
  interfaces: ens33                            #i    这个区域运行的网卡
  sources:                                     #i    
  services: cockpit dhcpv6-client ssh          #i    这个区域可以通过的服务
  ports:                                       #i    这个区域业已通过的端口(必须写成  端口/协议  如:800/tcp,8000/tcp)
  protocols:                                   #i    可以通过的协议(icmp)
  masquerade: no                               #i    地址伪装(类似于iptables的地址伪装)
  forward-ports:                               #i    端口转发(类似于iptables中的DNAT,添加一个端口转发就是添加一个DNAT)
  source-ports:                                #i    
  icmp-blocks:                                 #i    
  rich rules:                                  #i    添加富规则(禁止某一ip访问,允许某一ip访问等等)

上面列表的具体内容

[root@localhost ~]# firewall-cmd --help|grep -i target
  --get-target         Get the zone target [P only] [Z]
  --set-target=<target>
                       Set the zone target [P only] [Z]
[root@localhost ~]# firewall-cmd --help|grep -i icmp-block-inversion
  --add-icmp-block-inversion
  --remove-icmp-block-inversion
  --query-icmp-block-inversion
[root@localhost ~]# firewall-cmd --help|grep -i interfaces
  --get-default-zone   Print default zone for connections and interfaces
Options to Handle Bindings of Interfaces
  --list-interfaces    List interfaces that are bound to a zone [P] [Z]
[root@localhost ~]# firewall-cmd --help|grep -i sources
Options to Handle Bindings of Sources
  --list-sources       List sources that are bound to a zone [P] [Z]
[root@localhost ~]# firewall-cmd --help|grep -i services
  --get-services       Print predefined services [P]
  --list-services      List services added for a zone [P] [Z]
[root@localhost ~]# firewall-cmd --help|grep -i ports
  --service=<service> --get-ports
                       List ports of service [P only]
  --service=<service> --get-source-ports
                       List source ports of service [P only]
  --list-ports         List ports added for a zone [P] [Z]
  --list-source-ports  List source ports added for a zone [P] [Z]
  --list-forward-ports List IPv4 forward ports added for a zone [P] [Z]
  --helper=<helper> --get-ports
                       List ports of helper [P only]
[root@localhost ~]# firewall-cmd --help|grep -i protocols
  --service=<service> --get-protocols
                       List protocols of service [P only]
  --list-protocols     List protocols added for a zone [P] [Z]
[root@localhost ~]# firewall-cmd --help|grep -i masquerade
  --add-masquerade     Enable IPv4 masquerade for a zone [P] [Z] [T]
  --remove-masquerade  Disable IPv4 masquerade for a zone [P] [Z]
  --query-masquerade   Return whether IPv4 masquerading has been enabled for a
[root@localhost ~]# firewall-cmd --help|grep forward-port
  --list-forward-ports List IPv4 forward ports added for a zone [P] [Z]
  --add-forward-port=port=<portid>[-<portid>]:proto=<protocol>[:toport=<portid>[-<portid>]][:toaddr=<address>[/<mask>]]
  --remove-forward-port=port=<portid>[-<portid>]:proto=<protocol>[:toport=<portid>[-<portid>]][:toaddr=<address>[/<mask>]]
  --query-forward-port=port=<portid>[-<portid>]:proto=<protocol>[:toport=<portid>[-<portid>]][:toaddr=<address>[/<mask>]]
[root@localhost ~]# firewall-cmd --help|grep -i source-ports
  --service=<service> --get-source-ports
  --list-source-ports  List source ports added for a zone [P] [Z]
[root@localhost ~]# firewall-cmd --help|grep -i icmp-blocks
  --list-icmp-blocks   List Internet ICMP type blocks added for a zone [P] [Z]
[root@localhost ~]# firewall-cmd --help|grep rich
  --list-rich-rules    List rich language rules added for a zone [P] [Z]
  --add-rich-rule=<rule>
                       Add rich language rule 'rule' for a zone [P] [Z] [T]
  --remove-rich-rule=<rule>
                       Remove rich language rule 'rule' from a zone [P] [Z]
  --query-rich-rule=<rule>
                       Return whether a rich language rule 'rule' has been

某一区域的所有操作

[root@localhost ~]# firewall-cmd --zone=public --
--add-forward-port=            --list-sources
--add-icmp-block=              --query-forward-port=
--add-icmp-block-inversion     --query-icmp-block=
--add-interface=               --query-icmp-block-inversion
--add-masquerade               --query-interface=
--add-port=                    --query-masquerade
--add-protocol=                --query-port=
--add-rich-rule=               --query-protocol=
--add-service=                 --query-rich-rule=
--add-source=                  --query-service=
--add-source-port=             --query-source=
--change-interface=            --query-source-port=
--change-source=               --remove-forward-port=
--change-zone=                 --remove-icmp-block=
--get-description              --remove-icmp-block-inversion
--get-short                    --remove-interface=
--list-all                     --remove-masquerade
--list-forward-ports           --remove-port=
--list-icmp-blocks             --remove-protocol=
--list-interfaces              --remove-rich-rule=
--list-ports                   --remove-service=
--list-protocols               --remove-source=
--list-rich-rules              --remove-source-port=
--list-services                --set-description=
--list-source-ports            --set-short=
[root@localhost ~]# firewall-cmd --zone=public --
--add-forward-port=            --list-sources
--add-icmp-block=              --query-forward-port=
--add-icmp-block-inversion     --query-icmp-block=
--add-interface=               --query-icmp-block-inversion
--add-masquerade               --query-interface=
--add-port=                    --query-masquerade
--add-protocol=                --query-port=
--add-rich-rule=               --query-protocol=
--add-service=                 --query-rich-rule=
--add-source=                  --query-service=
--add-source-port=             --query-source=
--change-interface=            --query-source-port=
--change-source=               --remove-forward-port=
--change-zone=                 --remove-icmp-block=
--get-description              --remove-icmp-block-inversion
--get-short                    --remove-interface=
--list-all                     --remove-masquerade
--list-forward-ports           --remove-port=
--list-icmp-blocks             --remove-protocol=
--list-interfaces              --remove-rich-rule=
--list-ports                   --remove-service=
--list-protocols               --remove-source=
--list-rich-rules              --remove-source-port=
--list-services                --set-description=
--list-source-ports            --set-short=

区域内添加网卡:firewall-cmd --zone=public --add-interface=34或者firewall-cmd --zone=trusted --change-interface=ens33

firewall-config(图形界面)

  1. 安装firewall-config工具yum -y install firewall-config
  2. 启动图形界面firewall-config
    firewall-cmd --zone=trusted --change-interface=ens33`

firewall-config(图形界面)

  1. 安装firewall-config工具yum -y install firewall-config
  2. 启动图形界面firewall-config
    在这里插入图片描述
    iptables防火墙请看https://blog.csdn.net/tomorrow__nice/article/details/107820678
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值