Geavanceerd
Zoeken inInstallatiegidsen
Zo zoek je
  • Plak een foutmelding tussen aanhalingstekens, bijv. "permission denied", om de oplossingstabel te vinden.
  • Kies een gebied en een deel van de gids (installeren, eerste instellingen, dagelijks gebruik, beveiliging, oplossingen) om direct naar de juiste stap te gaan.
  • "twee woorden" vindt precies die zin.
  • Gewone woorden vinden namen, teksten en voorbeelden.
  • ↑ ↓ bewegen · Enter openen · Esc sluiten · / zoeken
Probeer:

Gids 31firewalld · Network

Install and set up firewalld

firewalld is the firewall of RHEL, Rocky, Alma and Fedora (and it works on Ubuntu too). Instead of long nftables rules you work with zones, services and sources: "this network may reach SSH, the internet may reach HTTPS". This guide installs and starts firewalld, explains runtime and permanent rules, opens services the safe way, limits access by source IP, adds rich rules, port forwarding and logging, and shows how to test a rule without locking yourself out.

  • 12 Lessen
  • 10 Commando's

Dit deel is nog niet vertaald. Je ziet de Engelse tekst.

$ als gewone gebruiker# als root (of met sudo)

31.1

Know it before you install

Every network interface (and every source network) belongs to one zone. A zone lists what is allowed in. A service is a named set of ports (ssh = 22/tcp, https = 443/tcp). firewalld writes the real rules into nftables.

ItemValue
Packagefirewalld
Servicefirewalld.service
Commandfirewall-cmd (and firewall-config GUI, firewall-offline-cmd)
Main config/etc/firewalld/firewalld.conf
Your zones and services/etc/firewalld/zones/*.xml, /etc/firewalld/services/*.xml
Built-in defaults/usr/lib/firewalld/ (do not edit)
Backendnftables

Onthoud

Runtime rules work at once but are lost at reload or reboot. Permanent rules (--permanent) are saved but work only after --reload. The normal way: add with --permanent, then --reload.

31.2

Install on RHEL, Rocky, Alma and Fedora

It is usually installed and running already:

dnf -y install firewalld
systemctl enable --now firewalld
firewall-cmd --state
running

31.3

Install on Ubuntu and Debian

Ubuntu uses UFW by default. Use only one firewall tool — turn UFW off first:

ufw disable
apt-get update
apt-get install -y firewalld
systemctl enable --now firewalld
firewall-cmd --add-service=ssh --permanent && firewall-cmd --reload

31.4

First configuration: know your zones

firewall-cmd --get-default-zone
public
firewall-cmd --get-active-zones
public
  interfaces: eth0
firewall-cmd --list-all
public (active)
  target: default
  interfaces: eth0
  services: cockpit dhcpv6-client ssh
  ports:
  sources:
  rich rules:

The first settings on a new server:

  1. Remove services you do not need (for example cockpit, dhcpv6-client on a server with a fixed IP).
  2. Open only the services this server offers.
  3. Put admin access (SSH) on a zone that only your admin network can reach.
  4. Turn on logging of denied packets while you build the rules.
firewall-cmd --permanent --remove-service=cockpit
firewall-cmd --permanent --remove-service=dhcpv6-client
firewall-cmd --permanent --add-service={http,https}
firewall-cmd --reload
firewall-cmd --list-services
http https ssh

31.5

Limit access by source network

Allow SSH only from the admin network: put that network in the internal zone with SSH, and remove SSH from public:

firewall-cmd --permanent --zone=internal --add-source=10.0.0.0/24
firewall-cmd --permanent --zone=internal --add-service=ssh
firewall-cmd --permanent --zone=public --remove-service=ssh
firewall-cmd --reload
firewall-cmd --get-active-zones
internal
  sources: 10.0.0.0/24
public
  interfaces: eth0

Let op

Do this from a session inside 10.0.0.0/24, or test first with a timed runtime rule (below). Otherwise you lock yourself out.

31.6

Ports, rich rules and forwarding

A port that has no service name, and a custom service for your app:

firewall-cmd --permanent --add-port=8443/tcp
firewall-cmd --permanent --new-service=shopapi
firewall-cmd --permanent --service=shopapi --set-description="Shop API"
firewall-cmd --permanent --service=shopapi --add-port=9000/tcp
firewall-cmd --permanent --add-service=shopapi

Rich rules for "this IP to this port", rate limits and blocks:

firewall-cmd --permanent --add-rich-rule='rule family="ipv4" source address="10.0.1.0/24" port port="5432" protocol="tcp" accept'
firewall-cmd --permanent --add-rich-rule='rule family="ipv4" source address="203.0.113.50" drop'
firewall-cmd --permanent --add-rich-rule='rule service name="ssh" accept limit value="10/m"'
firewall-cmd --reload
firewall-cmd --list-rich-rules

Port forwarding and NAT (for a gateway or a container host):

firewall-cmd --permanent --add-forward-port=port=80:proto=tcp:toport=8080
firewall-cmd --permanent --add-masquerade

31.7

Test safely and log

A runtime rule with a timeout removes itself — perfect to test without risk:

firewall-cmd --add-service=http --timeout=5m
firewall-cmd --set-log-denied=unicast
journalctl -k -f | grep -i 'filter_'
firewall-cmd --runtime-to-permanent

--runtime-to-permanent saves the runtime rules you tested. Set --set-log-denied=off again when you are done (logs can get big).

31.8

Daily use: the commands and the real uses

firewall-cmd --list-all
firewall-cmd --list-all-zones | less
firewall-cmd --info-service=https
firewall-cmd --get-services | tr ' ' '\n' | grep -i sql
firewall-cmd --zone=public --query-service=http
firewall-cmd --permanent --zone=internal --change-interface=eth1
nmcli connection modify eth1 connection.zone internal
firewall-cmd --panic-on
firewall-cmd --panic-off

--panic-on drops all traffic at once (an emergency stop — also your SSH session).

Real uses at work:

  • Every RHEL server: only the needed services open; admin ports only from the admin network.
  • Database servers: rich rules for the app subnet only.
  • RHCSA exam tasks: open services and ports permanently, with SELinux ports.

31.9

Make it safe

Security checklist:

  • Default zone public (or drop for very strict servers); only needed services.
  • SSH and admin ports only from admin networks (sources or rich rules).
  • Always --permanent + --reload; check with --list-all after every change.
  • Use one firewall tool only (not firewalld + UFW + manual nftables).
  • Docker writes its own rules and publishes ports past firewalld zones — bind container ports to 127.0.0.1 when a proxy is in front.
  • Keep the config in Git (the XML files in /etc/firewalld/) or in Ansible (ansible.posix.firewalld).

31.10

Update and remove

dnf -y upgrade firewalld
systemctl disable --now firewalld
dnf -y remove firewalld

Do not remove the firewall on a public server without another firewall in front (cloud security group).

31.11

Fix common problems

ProblemCauseFix
Rule is gone after reload or rebootIt was a runtime rule only.Add with --permanent (or --runtime-to-permanent), then --reload.
--permanent rule does not workNo reload yet.firewall-cmd --reload.
Service works on the server but not from other hostsThe port is not open in the zone of the interface.firewall-cmd --get-active-zones; add the service to that zone.
Rule in a zone has no effectThe interface or source is in another zone.--get-active-zones; move the interface (--change-interface or nmcli … connection.zone).
Error: INVALID_SERVICE: 'xyz'No service with that name.firewall-cmd --get-services; use --add-port or create the service.
Locked out of SSHSSH removed from the zone of your source.Use the console; test changes with --timeout first next time.
Container ports open although the zone does not allow themDocker's own rules.Bind with -p 127.0.0.1:…; use the docker zone rules carefully.

31.12

Next steps

1You added a rule with --permanent and it does not work yet. Why?

Permanent rules work only after firewall-cmd --reload.

2How do you test a rule so it removes itself if something goes wrong?

Add it as a runtime rule with --timeout=5m.

Alle commando's in dit hoofdstuk