Firewall-cmd Commands
Firewalld firewall-cmd commands for RHEL/CentOS/Fedora firewall management.
Basic Operations
firewall-cmd --stateCheck if firewalld is running
firewall-cmd --get-active-zonesList active zones
firewall-cmd --get-default-zoneShow default zone
firewall-cmd --list-allList all settings for default zone
firewall-cmd --list-all-zonesList all settings for all zones
firewall-cmd --reloadReload firewall rules
firewall-cmd --complete-reloadComplete reload (drops connections)
systemctl start firewalldStart firewalld service
systemctl stop firewalldStop firewalld service
systemctl enable firewalldEnable firewalld at boot
systemctl disable firewalldDisable firewalld at boot
Zone Management
firewall-cmd --get-zonesList all available zones
firewall-cmd --set-default-zone=publicSet default zone to public
firewall-cmd --zone=public --list-allList all settings for public zone
firewall-cmd --get-zone-of-interface=eth0Get zone of interface
firewall-cmd --zone=public --add-interface=eth0Add interface to zone
firewall-cmd --zone=public --change-interface=eth0Change interface zone
firewall-cmd --zone=public --remove-interface=eth0Remove interface from zone
firewall-cmd --new-zone=custom --permanentCreate new zone
firewall-cmd --delete-zone=custom --permanentDelete zone
Service Management
firewall-cmd --get-servicesList all available services
firewall-cmd --list-servicesList enabled services in default zone
firewall-cmd --zone=public --list-servicesList services in specific zone
firewall-cmd --add-service=httpAdd HTTP service (temporary)
firewall-cmd --add-service=http --permanentAdd HTTP service (permanent)
firewall-cmd --remove-service=httpRemove HTTP service (temporary)
firewall-cmd --remove-service=http --permanentRemove HTTP service (permanent)
firewall-cmd --zone=public --add-service=https --permanentAdd HTTPS to public zone
firewall-cmd --info-service=sshShow service information
Port Management
firewall-cmd --list-portsList open ports in default zone
firewall-cmd --add-port=8080/tcpOpen TCP port 8080 (temporary)
firewall-cmd --add-port=8080/tcp --permanentOpen TCP port 8080 (permanent)
firewall-cmd --add-port=5000-5100/tcp --permanentOpen TCP port range
firewall-cmd --remove-port=8080/tcpClose TCP port 8080 (temporary)
firewall-cmd --remove-port=8080/tcp --permanentClose TCP port 8080 (permanent)
firewall-cmd --zone=public --add-port=443/tcp --permanentOpen port in specific zone
firewall-cmd --add-port=53/udp --permanentOpen UDP port 53 (DNS)
Rich Rules
firewall-cmd --list-rich-rulesList all rich rules
firewall-cmd --add-rich-rule='rule family="ipv4" source address="192.168.1.0/24" accept'Accept from subnet
firewall-cmd --add-rich-rule='rule family="ipv4" source address="10.0.0.1" reject'Reject specific IP
firewall-cmd --add-rich-rule='rule service name="ssh" accept' --permanentAccept SSH service
firewall-cmd --add-rich-rule='rule port port="8080" protocol="tcp" accept'Accept TCP port 8080
firewall-cmd --add-rich-rule='rule family="ipv4" source address="192.168.1.100" port port="22" protocol="tcp" accept'Accept SSH from specific IP
firewall-cmd --remove-rich-rule='rule family="ipv4" source address="10.0.0.1" reject'Remove rich rule
Source Management
firewall-cmd --list-sourcesList source addresses
firewall-cmd --add-source=192.168.1.0/24Add source subnet
firewall-cmd --add-source=192.168.1.0/24 --permanentAdd source subnet (permanent)
firewall-cmd --remove-source=192.168.1.0/24Remove source subnet
firewall-cmd --zone=trusted --add-source=10.0.0.0/8 --permanentAdd source to trusted zone
firewall-cmd --get-zone-of-source=192.168.1.100Get zone of source IP
Port Forwarding
firewall-cmd --list-forward-portsList port forwarding rules
firewall-cmd --add-forward-port=port=80:proto=tcp:toport=8080Forward port 80 to 8080
firewall-cmd --add-forward-port=port=80:proto=tcp:toport=8080:toaddr=192.168.1.100Forward to different host
firewall-cmd --remove-forward-port=port=80:proto=tcp:toport=8080Remove port forward
firewall-cmd --add-masqueradeEnable masquerading (NAT)
firewall-cmd --remove-masqueradeDisable masquerading
firewall-cmd --query-masqueradeCheck if masquerading is enabled
ICMP Management
firewall-cmd --get-icmptypesList available ICMP types
firewall-cmd --list-icmp-blocksList blocked ICMP types
firewall-cmd --add-icmp-block=echo-requestBlock ping requests
firewall-cmd --add-icmp-block=echo-request --permanentBlock ping (permanent)
firewall-cmd --remove-icmp-block=echo-requestUnblock ping requests
firewall-cmd --add-icmp-block-inversionInvert ICMP block (allow only listed)
Direct Rules
firewall-cmd --direct --get-all-rulesList all direct rules
firewall-cmd --direct --add-rule ipv4 filter INPUT 0 -p tcp --dport 9000 -j ACCEPTAdd direct iptables rule
firewall-cmd --direct --remove-rule ipv4 filter INPUT 0 -p tcp --dport 9000 -j ACCEPTRemove direct rule
firewall-cmd --direct --add-chain ipv4 filter CUSTOM_CHAINAdd custom chain
firewall-cmd --direct --get-chains ipv4 filterList chains
Panic Mode
firewall-cmd --panic-onEnable panic mode (drop all traffic)
firewall-cmd --panic-offDisable panic mode
firewall-cmd --query-panicCheck if panic mode is enabled
Lockdown
firewall-cmd --lockdown-onEnable lockdown mode
firewall-cmd --lockdown-offDisable lockdown mode
firewall-cmd --query-lockdownCheck lockdown status
Configuration Files
ls /etc/firewalld/zones/List zone configuration files
ls /etc/firewalld/services/List service configuration files
cat /etc/firewalld/firewalld.confView main configuration
firewall-cmd --runtime-to-permanentMake runtime config permanent
firewall-cmd --permanent --list-allShow permanent configuration