运行时配置
永久配置
firewall-config图形工具的工作流程
[root@localhost ~]# systemctl stop firewalld
[root@localhost ~]# firewall-cmd --statenot running
[root@localhost ~]# systemctl restart firewalld
[root@localhost ~]# firewall-cmd --staterunning
[root@localhost ~]#
[root@localhost ~]# firewall-cmd --reload
success
//状态信息将会丢失,多用于处理防火墙出现问题
[root@localhost ~]# firewall-cmd --complete-reload
success
[root@localhost ~]#
[root@localhost ~]# firewall-cmd --get-zones
block dmz drop external home internal public trusted work
//查看预定义的区域
[root@localhost ~]# firewall-cmd --get-service
RH-Satellite-6 amanda-client amanda-k5-client bacula bacula-client bitcoin bitcoin-rpc bitcoin-testnet bitcoin-testnet-rpc ceph ceph-mon cfengine condor-collector ctdb dhcp dhcpv6 dhcpv6-client dns docker-registry dropbox-lansync elasticsearch freeipa-ldap freeipa-ldaps freeipa-replication freeipa-trust ftp ganglia-client ganglia-master high-availability http https imap imaps ipp ipp-client ipsec iscsi-target kadmin kerberos kibana klogin kpasswd kshell ldap ldaps libvirt libvirt-tls managesieve mdns mosh mountd ms-wbt mssql mysql nfs nrpe ntp open ovirt-imageio ovirt-storageconsole ovirt-vmconsole pmcd pmproxy pmwebapi pmwebapis pop3 pop3s postgresql privoxy proxy-dhcp ptp pulseaudio puppetmaster quassel radius rpc-bind rsh rsyncd samba samba-client sane sip sips smtp smtp-submission smtps snmp snmptrap spideroak-lansync squid ssh synergy syslog syslog-tls telnet tftp tftp-client tinc tor-socks transmission-client vdsm vnc-server wbem-https xmpp-bosh xmpp-client xmpp-local xmpp-server
//查看预定义的服务
[root@localhost ~]# firewall-cmd --get-icmptypes
address-unreachable bad-header communication-prohibited destination-unreachable echo-reply echo-request fragmentation-needed host-precedence-violation host-prohibited host-redirect host-unknown host-unreachable ip-header-bad neighbour-advertisement neighbour-solicitation network-prohibited network-redirect network-unknown network-unreachable no-route packet-too-big parameter-problem port-unreachable precedence-cutoff protocol-unreachable redirect required-option-missing router-advertisement router-solicitation source-quench source-route-failed time-exceeded timestamp-reply timestamp-request tos-host-redirect tos-host-unreachable tos-network-redirect tos-network-unreachable ttl-zero-during-reassembly ttl-zero-during-transit unknown-header-type unknown-option
//查看预定义的icmp类型
[root@localhost ~]# firewall-cmd --get-default-zone
public
[root@localhost ~]#
[root@localhost ~]# firewall-cmd --set-default-zone=internal
success
[root@localhost ~]# firewall-cmd --get-default-zone
internal
[root@localhost ~]#
[root@localhost ~]# firewall-cmd --get-active-zones
internal
interfaces: ens33
[root@localhost ~]#
[root@localhost ~]# firewall-cmd --get-zone-of-interface=ens33
internal
[root@localhost ~]#
[root@localhost ~]# firewall-cmd --zone=work --add-interface=ens33
The interface is under control of NetworkManager, setting zone to 'work'.
success
[root@localhost ~]# firewall-cmd --get-default-zone
internal
[root@localhost ~]#
[root@localhost ~]# firewall-cmd --zone=work --remove-interface=ens33
The interface is under control of NetworkManager, setting zone to default.
success
[root@localhost ~]# firewall-cmd --get-active-zones
internal
interfaces: ens33
[root@localhost ~]#
[root@localhost ~]# firewall-cmd --zone=work --query-interface=ens33
no
[root@localhost ~]# firewall-cmd --zone=internal --query-interface=ens33
yes
[root@localhost ~]#
[root@localhost ~]# firewall-cmd --zone=internal --list-all
internal (active)
target: default
icmp-block-inversion: no
interfaces: ens33
sources:
services: ssh mdns samba-client dhcpv6-client
ports:
protocols:
masquerade: no
forward-ports:
source-ports:
icmp-blocks:
rich rules:
[root@localhost ~]#
[root@localhost ~]# firewall-cmd --zone=internal --list-services
ssh mdns samba-client dhcpv6-client
[root@localhost ~]#
[root@localhost ~]# firewall-cmd --zone=internal --list-services
ssh mdns samba-client dhcpv6-client
[root@localhost ~]# firewall-cmd --zone=internal --remove-service=ssh
success
[root@localhost ~]# firewall-cmd --zone=internal --list-services
mdns samba-client dhcpv6-client
[root@localhost ~]#
[root@localhost ~]# firewall-cmd --zone=internal --query-service=ssh
no
[root@localhost ~]#
[root@localhost ~]# firewall-cmd --zone=internal --list-ports
[root@localhost ~]#
[root@localhost ~]# firewall-cmd --zone=internal --add-port=22/tcp --timeout=5m
success
[root@localhost ~]# firewall-cmd --zone=internal --list-ports
22/tcp
[root@localhost ~]#
[root@localhost ~]# firewall-cmd --zone=internal --list-ports
22/tcp
[root@localhost ~]# firewall-cmd --zone=internal --remove-port=22/tcp
success
[root@localhost ~]# firewall-cmd --zone=internal --list-ports
[root@localhost ~]#
[root@localhost ~]# firewall-cmd --zone=internal --query-port=22/tcp
no
[root@localhost ~]#
[root@localhost ~]# firewall-cmd --zone=work --list-icmp-blocks
[root@localhost ~]#
[root@localhost ~]# firewall-cmd --zone=work --add-icmp-block=echo-reply
success
[root@localhost ~]# firewall-cmd --zone=work --list-icmp-blocks
echo-reply
[root@localhost ~]#
[root@localhost ~]# firewall-cmd --zone=work --remove-icmp-block=echo-reply
success
[root@localhost ~]# firewall-cmd --zone=work --list-icmp-blocks
[root@localhost ~]#
[root@a ~]# firewall-cmd --zone=work --query-icmp-block=echo-request
no
[root@a ~]#