Chapter 20: The firewall

firewalld cheat sheet

The chapter on one page: what to remember, the commands to have at your fingertips, and flashcards for quick revision.

The chapter in eight sentences

Cheat sheet

Look

CommandDoes
firewall-cmd --stateIs firewalld running
--get-default-zone · --get-active-zonesZones
--list-all [--zone=Z]Everything a zone allows
--get-zone-of-source=IPZone of an address
--info-service=NAME · --get-servicesService definitions
--query-service=NAMEyes or no (add --permanent for the saved rules)

Change

CommandDoes
--permanent --add-service=http · --reloadAllow a service for good
--permanent --add-port=9000/tcpAllow a port
--remove-service · --remove-portClose again
--add-port=8080/tcp --timeout=60Temporary
--runtime-to-permanentSave all runtime rules
--permanent --new-zone=Z · --reloadNew zone

Special

CommandDoes
--permanent --zone=Z --add-source=IPSend a host to a zone
--permanent --new-service=S · --service=S --add-port=9000/tcpOwn service
--add-forward-port=port=8081:proto=tcp:toport=8080Forward a port
--add-rich-rule='rule family="ipv4" source address="IP" port port="9000" protocol="tcp" reject'Rich rule
--set-log-denied=all · journalctl -kLog rejections
ss -tlnp · curl -m 3 URLListening ports, client test

Flashcards

Is the firewall up, and which zone?
firewall-cmd --state · --get-default-zone · --get-active-zones
Show everything an active zone allows?
firewall-cmd --list-all [--zone=NAME]
Which zone judges a packet?
Source match first, then interface, then the default zone.
Allow a service permanently?
firewall-cmd --permanent --add-service=http; firewall-cmd --reload
Allow a port?
firewall-cmd --permanent --add-port=9000/tcp; firewall-cmd --reload
Runtime versus permanent?
Without --permanent: now only. With it: saved only. --reload loads the saved state.
A rule for a test?
firewall-cmd --add-port=8080/tcp --timeout=60
Danger of --runtime-to-permanent?
It saves every temporary change too.
Only one host may connect?
New zone + --add-source=IP + --add-service, then --reload.
Forward a port?
--add-forward-port=port=8081:proto=tcp:toport=8080
Symptoms?
No route to host = rejected · timeout = dropped · refused = nothing listening
Debug order?
Service running → listening (ss -tlnp) → zone rules → SELinux port label; log with --set-log-denied=all.