Dit deel is nog niet vertaald. Je ziet de Engelse tekst.
Wat het doet
firewall-cmd talks to the firewalld service. Changes without --permanent work at once but are lost at reload or reboot; with --permanent they are saved but only active after --reload. Most options follow one pattern: --add-X, --remove-X, --query-X, --list-X, optionally with --zone=ZONE (default: the default zone).
Zo schrijf je het
firewall-cmd [--permanent] [--zone=ZONE] OPTION...
firewall-cmd --reload | --state | --list-allOpties 43
Meest gebruikt
General
Zones
Zone content
--add-service=SERVICE,--remove-service=SERVICE,--query-service=SERVICE,--list-services- Services in the zone.
--add-source=ADDR[/MASK]|ipset:NAME,--remove-source=…,--query-source=…,--list-sources- Bind source networks to the zone.
--add-interface=IF,--remove-interface=IF,--change-interface=IF,--query-interface=IF,--list-interfaces- Interfaces of the zone.
--add-rich-rule='RULE',--remove-rich-rule='RULE',--query-rich-rule='RULE',--list-rich-rules- Detailed rules.
--add-forward-port=port=P:proto=tcp[:toport=P][:toaddr=A],--remove-forward-port=…,--list-forward-ports- Port forwarding.
Services, ipsets, helpers, icmptypes
Emergency and lockdown
Niets past bij dit filter.
Voorbeelden 12
$ als gewone gebruiker# als root (of met sudo)
1What is open?
firewall-cmd --list-all public (active) interfaces: enp1s0 services: cockpit dhcpv6-client ssh ports: rich rules:The default zone on RHEL.
2Open a service permanently
firewall-cmd --add-service=http --permanent firewall-cmd --reloadSurvives reboots.
3Open a port
firewall-cmd --add-port=82/tcp --permanent; firewall-cmd --reloadFor non-standard ports (also fix SELinux!).
4Close a service
firewall-cmd --remove-service=cockpit --permanent; firewall-cmd --reloadSmaller attack surface.
5Test a rule for 5 minutes
firewall-cmd --add-port=9090/tcp --timeout=5mRemoved automatically.
6Trust an admin network
firewall-cmd --zone=trusted --add-source=192.168.122.0/24 --permanent; firewall-cmd --reloadEverything from that network is allowed.
7Service only for one network
firewall-cmd --permanent --add-rich-rule='rule family="ipv4" source address="10.0.0.0/24" service name="ssh" accept'Combine with removing ssh from the zone.
8Block one address
firewall-cmd --permanent --add-rich-rule='rule family="ipv4" source address="203.0.113.50" drop'; firewall-cmd --reloadAn attacker from the logs.
9Port forwarding
firewall-cmd --permanent --add-forward-port=port=80:proto=tcp:toport=8080; firewall-cmd --reloadPort 80 goes to 8080 on the same host.
10Save runtime changes
firewall-cmd --runtime-to-permanentWhen you tested without --permanent.
11Which ports does a service open?
firewall-cmd --info-service=sambaports: 139/tcp 445/tcp …
12Log denied packets (security)
firewall-cmd --set-log-denied=all journalctl -k -f | grep REJECTSee what is blocked.
Niets past bij dit filter.
Let op
- --permanent changes are not active until --reload; runtime changes are lost at reload.
- --panic-on cuts your SSH session.
Bestanden
/etc/firewalld/- Your saved config (zones, services).
/usr/lib/firewalld/- Default zones and services.
/etc/firewalld/firewalld.conf- DefaultZone, backend, logging.
Exitcodes
0 :: Done (query: yes). 1 :: Query: no. 2 :: Wrong use. 252 :: firewalld is not running.