firewalld-cmd(命令行模式)
firewall-cmd +下面内容
--state # 显示firewalld的状态;
--reload # 不中断服务的重新加载;
--complete-reload # 中断所有连接的重新加载;
--runtime-to-permanent # 将当前防火墙的规则永久保存;
--check-config # 检查配置正确性;
firewalld的规则分为两种状态
- runtime运行时: 修改规则马上生效,但是是临时生效 [不建议]
firewall-cmd --add-forward-port=port=80:proto=tcp:toport=8080
firewall-cmd --runtime-to-permanent #没有这条命令重启计算机或重新加载后,上面的规则就不存在了
- permanent持久配置: 修改后需要reload重载才会生效 [强烈推荐]
firewall-cmd --permanent --zone=work --add-port=1000/tcp #重启电脑后规则依然存在
九个区域(zone)
- public(公共区域):不相信网络上的人和计算机,不会损害你的计算机
- block(阻塞区域):人和传入的网络数据包都会将被阻止
- work(工作区域):相信网络上的其他计算机,不会损害你的计算机
- home(家庭区域):相信网络上的任何计算机,不会损害你的计算机
- DMZ(隔离区域):隔离区域也称为非军事区域,内外网络之间增加的一层网络,起到缓冲作用。对于隔离区域,只有选择接受传入的网络连接
- trusted(信任区域):所有网络连接都可以接受
- drop(丢弃区域):人和传入的网络连接都被拒绝
- intermal(内部区域):信任网络上的其他计算机,不会损害你的计算机。只有选择接受传入的网络连接
- 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(图形界面)
- 安装firewall-config工具
yum -y install firewall-config
- 启动图形界面
firewall-config
firewall-cmd --zone=trusted --change-interface=ens33`
firewall-config(图形界面)
- 安装firewall-config工具
yum -y install firewall-config
- 启动图形界面
firewall-config
iptables防火墙请看https://blog.csdn.net/tomorrow__nice/article/details/107820678