[root@localhost ~]# firewall-cmd --get-default-zone public #查询当前默认区域 [root@localhost ~]# firewall-cmd --set-default-zone= #设置默认区域。会同时更改运行时配置和永久配置 [root@localhost ~]# firewall-cmd --get-zones block dmz drop external home internal public trusted work #列出所有可用区域 [root@localhost ~]# firewall-cmd --get-services amanda-client bacula bacula-client dhcp dhcpv6 dhcpv6-client dns ftp high-availability http https imaps ipp ipp-client ipsec kerberos kpasswd ldap ldaps libvirt libvirt-tls mdns mountd ms-wbt mysql nfs ntp openvpn pmcd pmproxy pmwebapi pmwebapis pop3s postgresql proxy-dhcp radius rpc-bind samba samba-client smtp ssh telnet tftp tftp-client transmission-client vnc-server wbem-https #列出所有预定义服务 [root@localhost ~]# firewall-cmd --get-active-zones public interfaces: eno16777736 virbr0 #列出当前正在使用的区域 [root@localhost ~]# firewall-cmd --list-all-zones #列出所有区域所有已配置接口、源、服务和端口信息 [root@localhost ~]# firewall-cmd --list-all public (default, active) interfaces: eno16777736 virbr0 sources: services: dhcpv6-client ssh ports: masquerade: no forward-ports: icmp-blocks: rich rules: #列出默认区域所有已配置接口、源、服务和端口信息 [root@localhost ~]# firewall-cmd --list-all --zone=home home interfaces: sources: services: dhcpv6-client ipp-client mdns samba-client ssh ports: masquerade: no forward-ports: icmp-blocks: rich rules: #列出指定区域的信息。--zone=home --permanent :下次开机生效 --runtime :立即生效 --reload :加载配置文件。可先--permanent,再reload。
[root@localhost ~]# firewall-cmd --add-service=http #添加http服务 [root@localhost ~]# firewall-cmd --remove-service=http #删除http服务 [root@localhost ~]# firewall-cmd --add-port=80/tcp #添加tcp协议的80端口(效果同打开http服务) [root@localhost ~]# firewall-cmd --list-all public (default, active) interfaces: eno16777736 eno33554992 team0 sources: services: dhcpv6-client ssh ports: 80/tcp ### masquerade: no forward-ports: icmp-blocks: rich rules: [root@localhost ~]# firewall-cmd --add-rich-rule='rule family="ipv4" source address="172.17.8.59" service name="ssh" reject' success #添加富规则。格式请man 5 firewalld.richlanguage [root@localhost ~]# firewall-cmd --list-all public (default, active) interfaces: eno16777736 virbr0 sources: services: dhcpv6-client ssh ports: masquerade: no forward-ports: icmp-blocks: rich rules: rule family="ipv4" source address="172.17.8.59" service name="ssh" reject [root@localhost ~]# firewall-cmd --remove-rich-rule='rule family="ipv4" source address="172.17.8.59" service name="ssh" reject' #删除此富规则 success
forward-ports:端口转发
[root@localhost ~]# firewall-cmd --add-rich-rule='rule family="ipv4" forward-port port="5423" protocol="tcp" to-port="80" to-addr="172.25.0.10"' success [root@localhost ~]# firewall-cmd --add-masquerade #要打开伪装 success [root@localhost ~]# firewall-cmd --list-all public (default, active) interfaces: eno16777736 virbr0 sources: services: dhcpv6-client ssh ports: masquerade: yes forward-ports: icmp-blocks: rich rules: rule family="ipv4" forward-port port="5423" protocol="tcp" to-port="80" to-addr="172.25.0.10" #添加端口转发富规则
firewall-config:图形界面