Appearance
Using firewall-cmd for configuring Firewall in linux
The firewall-cmd command is used to configure and manage the firewalld service on Linux systems. It allows you to dynamically add, remove, and modify firewall rules without restarting the service.
Check Firewall status
bash
firewall-cmd --stateoutput:
runningListing Active Zones
Show all available zones and the default one:
bash
firewall-cmd --get-active-zonesoutput:
public
interfaces: eth0Allowing Service
Permit HTTP service in the public zone:
bash
firewall-cmd --zone=public --add-service=httpTo make it permanent after reboot, use param --permanent
bash
firewall-cmd --zone=public --add-service=http --permanentReload the firewall to apply permanent rules:
bash
firewall-cmd --reloadAllowing a Specific Port
Open port 5432/tcp temporarily:
bash
firewall-cmd --zone=public --add-port=5432/tcpMake it permanent:
bash
firewall-cmd --zone=public --add-port=5432/tcp --permanent
firewall-cmd --reloadBlocking a Service
Remove SSH access from the public zone:
bash
firewall-cmd --zone=public --remove-service=ssh --permanent
firewall-cmd --reloadListing All Rules
To see all active rules in the public zone:
bash
firewall-cmd --zone=public --list-alloutput:
bash
public (active)
target: default
interfaces: eth0
services: dhcpv6-client http https ssh
ports: 5432/tcp
masquerade: no
forward-ports:
icmp-blocks:
rich rules:Useful Flags
--permanent→ makes changes persistent across reboots.--reload→ reloads configuration to apply permanent changes.--list-all-zones→ displays rules for every zone.--runtime-to-permanent→ copies current runtime config into permanent rules.
Additional Notes
- firewall-cmd manages zones (trusted, public, internal, etc.), each with its own rules.
- Good practice: test rules without --permanent first, then apply permanently after confirming.
- Always keep a console session open when changing SSH rules, to avoid locking yourself out.