Ceci est une ancienne révision du document !
Table des matières
Version : 2026.01
Dernière mise-à-jour : 2025/11/24 11:11
LDF402 - Netfilter et Firewalld
Contenu du Module
- LDF402 - Netfilter et Firewalld
- Contenu du Module
- Les Problématiques
- L'IP Spoofing
- Déni de Service (DoS)
- SYN Flooding
- Flood
- Le Contre-Mesure
- Le Pare-feu Netfilter/iptables
- LAB #1 - La Configuration de Netfilter par firewalld
- 1.1 - La Configuration de Base de firewalld
- 1.2 - La Commande firewall-cmd
- 1.3 - La Configuration Avancée de firewalld
- 1.4 - Le mode Panic de firewalld
Les Problématiques
L'IP Spoofing
L'IP Spoofing consiste en faire croire à un serveur que sa machine possède une adresse IP autre que celle réellement attribuée. Le but de cette opération est de se placer en tant que point de passage obligatoire des paquets envoyés entre le serveur et le vrai propriétaire de l'adresse IP spoofée. Le mécanisme est la suivante :
- L'attaquant change son adresse IP en prenant une à laquelle le serveur cible fera confiance,
- L'attaquant envoie une requête au serveur en stipulant une route de communication qui passe par l'adresse IP réelle de l'attaquant,
- L'attaquant reprend son adresse IP réelle,
- Le serveur accepte la requête car elle provient d'une adresse IP à laquelle il peux faire confiance et renvoie une réponse en utilisant la route spécifiée par l'attaquant,
- Le client utilise la route spécifiée par l'attaquant pour répondre au serveur.
Déni de Service (DoS)
Une attaque de déni de service consiste à rendre inopérable une machine en lui envoyant une grande quantité de données inutiles. Un exemple de ce type d'attaque s'appelle un ping flood :
- L'attaquant prend l'adresse IP de sa cible,
- Il envoie ensuite un ping à une machine de diffusion,
- La machine de diffusion envoie ce même ping à un grand nombre de clients en spécifiant l'origine de la requête,
- L'attaquant reprend son adresse IP d'origine,
- Tous les clients renvoient une réponse au ping en même temps à la cible.
SYN Flooding
Le SYN Flooding, aussi appelé un SYN-ACK Attack, consiste à envoyer vers une cible de multiples paquets SYN très rapidement. La cible répond à chaque paquet reçu avec un paquet ACK et attend une réponse ACK de l'attaquant. A ce stade pour chaque ACK renvoyé par la cible, une connexion dite semi-ouverte existe entre les deux machines. La cible doit réserver une petite partie de sa mémoire pour chaque connexion semi-ouverte jusqu'au time-out de ladite semi-connexion. Si l'attaquant envoie très rapidement des paquets SYN, le système de time-out n'a pas la possibilité d'expirer les semi-connexions précédentes. Dans ce cas la mémoire de la cible se remplit et on obtient un buffer overflow.
Flood
Le Flood consiste à envoyer très rapidement de gros paquets ICMP vers la cible.
La Contre-Mesure
La contre-mesure est principalement l'utilisation d'un pare-feu.
Le Parefeu Netfilter
Présentation
Netfilter est composé de 5 hooks :
- NF_IP_PRE_ROUTING
- NF_IP_LOCAL_IN
- NF_IP_LOCAL_OUT
- NF_IP_FORWARD
- NF_IP_POSTROUTING
Ces hooks sont utilisés par deux branches, la première est celle concernée par les paquets qui entrent vers des services locaux :
- NF_IP_PRE_ROUTING > NF_IP_LOCAL_IN > NF_IP_LOCAL_OUT > NF_IP_POSTROUTING
tandis que la deuxième concerne les paquets qui traversent la passerelle:
- NF_IP_PRE_ROUTING > NF_IP_FORWARD > NF_IP_POSTROUTING
Si IPTABLES a été compilé en tant que module, son utilisation nécessite le chargement de plusieurs modules supplémentaires en fonction de la situation:
- iptable_filter
- iptable_mangle
- iptable_net
- etc
Netfilter est organisé en tables. La commande iptables de netfilter permet d'insérer des policies dans les chaines:
- La table FILTER
- La chaîne INPUT
- Concerne les paquets entrants
- Policies: ACCEPT, DROP, REJECT
- La chaîne OUTPUT
- Concerne les paquets sortants
- Policies: ACCEPT, DROP, REJECT
- La chaîne FORWARD
- Concerne les paquets traversant le par-feu.
- Policies: ACCEPT, DROP, REJECT
Si aucune table n'est précisée, c'est la table FILTER qui s'applique par défaut.
- La table NAT
- La chaîne PREROUTING
- Permet de faire la translation d'adresse de destination
- Cibles: SNAT, DNAT, MASQUERADE
- La chaîne POSTROUTING
- Permet de faire la translation d'adresse de la source
- Cibles: SNAT, DNAT, MASQUERADE
- Le cas spécifique OUTPUT
- Permet la modification de la destination des paquets générés localement
- La table MANGLE
- Permet le marquage de paquets générés localement (OUTPUT) et entrants (PREROUTING)
Les policies sont:
- ACCEPT
- Permet d'accepter le paquet concerné
- DROP
- Permet de rejeter le paquet concerné sans générer un message d'erreur
- REJECT
- Permet de rejeter le paquet concerné en générant une message d'erreur
Les cibles sont:
- SNAT
- Permet de modifier l'adresse source du paquet concerné
- DNAT
- Permet de modifier l'adresse de destination du paquet concerné
- MASQUERADE
- Permet de remplacer l'adresse IP privée de l'expéditeur par un socket public de la passerelle.
LAB #1 - La Configuration de Netfilter par firewalld
firewalld est à Netfilter ce que NetworkManager est au réseau. firewalld utilise des zones - des jeux de règles pré-définis dans lesquels sont placés les interfaces :
- trusted - un réseau fiable. Dans ce cas tous les ports sont autorisés,
- work, home, internal - un réseau partiellement fiable. Dans ce cas quelques ports sont autorisés,
- dmz, public, external - un réseau non fiable. Dans ce cas peu de ports sont autorisés,
- block, drop - tout est interdit. La zone drop n'envoie pas de messages d'erreurs.
Important - Une interface ne peut être que dans une zone à la fois tandis que plusieurs interfaces peuvent être dans la même zone.
Sous Debian 11, firewalld n'est pas installé par défaut :
root@debian11:~# apt-get -y install firewalld
Le service firewalld est déjà lancé et activé :
root@debian11:~# systemctl status firewalld.service
● firewalld.service - firewalld - dynamic firewall daemon
Loaded: loaded (/lib/systemd/system/firewalld.service; enabled; vendor preset: e>
Active: active (running) since Tue 2022-05-03 15:17:03 CEST; 11s ago
Docs: man:firewalld(1)
Main PID: 5695 (firewalld)
Tasks: 2 (limit: 4632)
Memory: 30.2M
CPU: 619ms
CGroup: /system.slice/firewalld.service
└─5695 /usr/bin/python3 /usr/sbin/firewalld --nofork --nopid
May 03 15:17:02 debian11.ittraining.loc systemd[1]: Starting firewalld - dynamic fire>
May 03 15:17:03 debian11.ittraining.loc systemd[1]: Started firewalld - dynamic firew>
lines 1-13/13 (END)
[q]
1.1 - La Configuration de Base de firewalld
La configuration par défaut de firewalld se trouve dans /usr/lib/firewalld :
root@debian11:~# ls -lR /usr/lib/firewalld/ /usr/lib/firewalld/: total 32 drwxr-xr-x 2 root root 4096 May 3 15:16 helpers drwxr-xr-x 2 root root 4096 May 3 15:16 icmptypes drwxr-xr-x 2 root root 4096 May 3 15:16 ipsets drwxr-xr-x 2 root root 4096 May 3 15:16 policies drwxr-xr-x 2 root root 12288 May 3 15:16 services drwxr-xr-x 2 root root 4096 May 3 15:16 zones /usr/lib/firewalld/helpers: total 52 -rw-r--r-- 1 root root 125 Feb 1 2021 amanda.xml -rw-r--r-- 1 root root 119 Feb 1 2021 ftp.xml -rw-r--r-- 1 root root 85 Feb 1 2021 h323.xml -rw-r--r-- 1 root root 134 Feb 1 2021 irc.xml -rw-r--r-- 1 root root 141 Feb 1 2021 netbios-ns.xml -rw-r--r-- 1 root root 136 Feb 1 2021 pptp.xml -rw-r--r-- 1 root root 90 Feb 1 2021 proto-gre.xml -rw-r--r-- 1 root root 122 Feb 1 2021 Q.931.xml -rw-r--r-- 1 root root 122 Feb 1 2021 RAS.xml -rw-r--r-- 1 root root 122 Feb 1 2021 sane.xml -rw-r--r-- 1 root root 158 Feb 1 2021 sip.xml -rw-r--r-- 1 root root 135 Feb 1 2021 snmp.xml -rw-r--r-- 1 root root 120 Feb 1 2021 tftp.xml /usr/lib/firewalld/icmptypes: total 180 -rw-r--r-- 1 root root 385 Feb 1 2021 address-unreachable.xml -rw-r--r-- 1 root root 258 Feb 1 2021 bad-header.xml -rw-r--r-- 1 root root 294 Feb 1 2021 beyond-scope.xml -rw-r--r-- 1 root root 279 Feb 1 2021 communication-prohibited.xml -rw-r--r-- 1 root root 222 Feb 1 2021 destination-unreachable.xml -rw-r--r-- 1 root root 173 Feb 1 2021 echo-reply.xml -rw-r--r-- 1 root root 210 Feb 1 2021 echo-request.xml -rw-r--r-- 1 root root 261 Feb 1 2021 failed-policy.xml -rw-r--r-- 1 root root 280 Feb 1 2021 fragmentation-needed.xml -rw-r--r-- 1 root root 266 Feb 1 2021 host-precedence-violation.xml -rw-r--r-- 1 root root 257 Feb 1 2021 host-prohibited.xml -rw-r--r-- 1 root root 242 Feb 1 2021 host-redirect.xml -rw-r--r-- 1 root root 239 Feb 1 2021 host-unknown.xml -rw-r--r-- 1 root root 247 Feb 1 2021 host-unreachable.xml -rw-r--r-- 1 root root 229 Feb 1 2021 ip-header-bad.xml -rw-r--r-- 1 root root 355 Feb 1 2021 neighbour-advertisement.xml -rw-r--r-- 1 root root 457 Feb 1 2021 neighbour-solicitation.xml -rw-r--r-- 1 root root 250 Feb 1 2021 network-prohibited.xml -rw-r--r-- 1 root root 248 Feb 1 2021 network-redirect.xml -rw-r--r-- 1 root root 239 Feb 1 2021 network-unknown.xml -rw-r--r-- 1 root root 247 Feb 1 2021 network-unreachable.xml -rw-r--r-- 1 root root 239 Feb 1 2021 no-route.xml -rw-r--r-- 1 root root 328 Feb 1 2021 packet-too-big.xml -rw-r--r-- 1 root root 225 Feb 1 2021 parameter-problem.xml -rw-r--r-- 1 root root 233 Feb 1 2021 port-unreachable.xml -rw-r--r-- 1 root root 256 Feb 1 2021 precedence-cutoff.xml -rw-r--r-- 1 root root 249 Feb 1 2021 protocol-unreachable.xml -rw-r--r-- 1 root root 185 Feb 1 2021 redirect.xml -rw-r--r-- 1 root root 244 Feb 1 2021 reject-route.xml -rw-r--r-- 1 root root 241 Feb 1 2021 required-option-missing.xml -rw-r--r-- 1 root root 227 Feb 1 2021 router-advertisement.xml -rw-r--r-- 1 root root 223 Feb 1 2021 router-solicitation.xml -rw-r--r-- 1 root root 248 Feb 1 2021 source-quench.xml -rw-r--r-- 1 root root 236 Feb 1 2021 source-route-failed.xml -rw-r--r-- 1 root root 253 Feb 1 2021 time-exceeded.xml -rw-r--r-- 1 root root 233 Feb 1 2021 timestamp-reply.xml -rw-r--r-- 1 root root 228 Feb 1 2021 timestamp-request.xml -rw-r--r-- 1 root root 258 Feb 1 2021 tos-host-redirect.xml -rw-r--r-- 1 root root 257 Feb 1 2021 tos-host-unreachable.xml -rw-r--r-- 1 root root 272 Feb 1 2021 tos-network-redirect.xml -rw-r--r-- 1 root root 269 Feb 1 2021 tos-network-unreachable.xml -rw-r--r-- 1 root root 293 Feb 1 2021 ttl-zero-during-reassembly.xml -rw-r--r-- 1 root root 256 Feb 1 2021 ttl-zero-during-transit.xml -rw-r--r-- 1 root root 259 Feb 1 2021 unknown-header-type.xml -rw-r--r-- 1 root root 249 Feb 1 2021 unknown-option.xml /usr/lib/firewalld/ipsets: total 4 -rw-r--r-- 1 root root 29 Feb 1 2021 README /usr/lib/firewalld/policies: total 4 -rw-r--r-- 1 root root 649 Feb 1 2021 allow-host-ipv6.xml /usr/lib/firewalld/services: total 700 -rw-r--r-- 1 root root 399 Feb 1 2021 amanda-client.xml -rw-r--r-- 1 root root 427 Feb 1 2021 amanda-k5-client.xml -rw-r--r-- 1 root root 283 Feb 1 2021 amqps.xml -rw-r--r-- 1 root root 273 Feb 1 2021 amqp.xml -rw-r--r-- 1 root root 285 Feb 1 2021 apcupsd.xml -rw-r--r-- 1 root root 301 Feb 1 2021 audit.xml -rw-r--r-- 1 root root 320 Feb 1 2021 bacula-client.xml -rw-r--r-- 1 root root 346 Feb 1 2021 bacula.xml -rw-r--r-- 1 root root 429 Feb 1 2021 bb.xml -rw-r--r-- 1 root root 339 Feb 1 2021 bgp.xml -rw-r--r-- 1 root root 275 Feb 1 2021 bitcoin-rpc.xml -rw-r--r-- 1 root root 307 Feb 1 2021 bitcoin-testnet-rpc.xml -rw-r--r-- 1 root root 281 Feb 1 2021 bitcoin-testnet.xml -rw-r--r-- 1 root root 244 Feb 1 2021 bitcoin.xml -rw-r--r-- 1 root root 410 Feb 1 2021 bittorrent-lsd.xml -rw-r--r-- 1 root root 294 Feb 1 2021 ceph-mon.xml -rw-r--r-- 1 root root 329 Feb 1 2021 ceph.xml -rw-r--r-- 1 root root 168 Feb 1 2021 cfengine.xml -rw-r--r-- 1 root root 211 Feb 1 2021 cockpit.xml -rw-r--r-- 1 root root 296 Feb 1 2021 collectd.xml -rw-r--r-- 1 root root 260 Feb 1 2021 condor-collector.xml -rw-r--r-- 1 root root 296 Feb 1 2021 ctdb.xml -rw-r--r-- 1 root root 305 Feb 1 2021 dhcpv6-client.xml -rw-r--r-- 1 root root 234 Feb 1 2021 dhcpv6.xml -rw-r--r-- 1 root root 227 Feb 1 2021 dhcp.xml -rw-r--r-- 1 root root 205 Feb 1 2021 distcc.xml -rw-r--r-- 1 root root 318 Feb 1 2021 dns-over-tls.xml -rw-r--r-- 1 root root 346 Feb 1 2021 dns.xml -rw-r--r-- 1 root root 374 Feb 1 2021 docker-registry.xml -rw-r--r-- 1 root root 391 Feb 1 2021 docker-swarm.xml -rw-r--r-- 1 root root 228 Feb 1 2021 dropbox-lansync.xml -rw-r--r-- 1 root root 338 Feb 1 2021 elasticsearch.xml -rw-r--r-- 1 root root 304 Feb 1 2021 etcd-client.xml -rw-r--r-- 1 root root 304 Feb 1 2021 etcd-server.xml -rw-r--r-- 1 root root 224 Feb 1 2021 finger.xml -rw-r--r-- 1 root root 270 Feb 1 2021 foreman-proxy.xml -rw-r--r-- 1 root root 408 Feb 1 2021 foreman.xml -rw-r--r-- 1 root root 709 Feb 1 2021 freeipa-4.xml -rw-r--r-- 1 root root 489 Feb 1 2021 freeipa-ldaps.xml -rw-r--r-- 1 root root 488 Feb 1 2021 freeipa-ldap.xml -rw-r--r-- 1 root root 242 Feb 1 2021 freeipa-replication.xml -rw-r--r-- 1 root root 657 Feb 1 2021 freeipa-trust.xml -rw-r--r-- 1 root root 361 Feb 1 2021 ftp.xml -rw-r--r-- 1 root root 184 Feb 1 2021 ganglia-client.xml -rw-r--r-- 1 root root 176 Feb 1 2021 ganglia-master.xml -rw-r--r-- 1 root root 212 Feb 1 2021 git.xml -rw-r--r-- 1 root root 218 Feb 1 2021 grafana.xml -rw-r--r-- 1 root root 119 Feb 1 2021 gre.xml -rw-r--r-- 1 root root 608 Feb 1 2021 high-availability.xml -rw-r--r-- 1 root root 448 Feb 1 2021 https.xml -rw-r--r-- 1 root root 353 Feb 1 2021 http.xml -rw-r--r-- 1 root root 372 Feb 1 2021 imaps.xml -rw-r--r-- 1 root root 327 Feb 1 2021 imap.xml -rw-r--r-- 1 root root 454 Feb 1 2021 ipp-client.xml -rw-r--r-- 1 root root 427 Feb 1 2021 ipp.xml -rw-r--r-- 1 root root 894 Feb 1 2021 ipsec.xml -rw-r--r-- 1 root root 255 Feb 1 2021 ircs.xml -rw-r--r-- 1 root root 247 Feb 1 2021 irc.xml -rw-r--r-- 1 root root 264 Feb 1 2021 iscsi-target.xml -rw-r--r-- 1 root root 358 Feb 1 2021 isns.xml -rw-r--r-- 1 root root 213 Feb 1 2021 jenkins.xml -rw-r--r-- 1 root root 182 Feb 1 2021 kadmin.xml -rw-r--r-- 1 root root 272 Feb 1 2021 kdeconnect.xml -rw-r--r-- 1 root root 233 Feb 1 2021 kerberos.xml -rw-r--r-- 1 root root 384 Feb 1 2021 kibana.xml -rw-r--r-- 1 root root 249 Feb 1 2021 klogin.xml -rw-r--r-- 1 root root 221 Feb 1 2021 kpasswd.xml -rw-r--r-- 1 root root 182 Feb 1 2021 kprop.xml -rw-r--r-- 1 root root 242 Feb 1 2021 kshell.xml -rw-r--r-- 1 root root 308 Feb 1 2021 kube-apiserver.xml -rw-r--r-- 1 root root 232 Feb 1 2021 ldaps.xml -rw-r--r-- 1 root root 199 Feb 1 2021 ldap.xml -rw-r--r-- 1 root root 385 Feb 1 2021 libvirt-tls.xml -rw-r--r-- 1 root root 389 Feb 1 2021 libvirt.xml -rw-r--r-- 1 root root 269 Feb 1 2021 lightning-network.xml -rw-r--r-- 1 root root 324 Feb 1 2021 llmnr.xml -rw-r--r-- 1 root root 349 Feb 1 2021 managesieve.xml -rw-r--r-- 1 root root 432 Feb 1 2021 matrix.xml -rw-r--r-- 1 root root 424 Feb 1 2021 mdns.xml -rw-r--r-- 1 root root 245 Feb 1 2021 memcache.xml -rw-r--r-- 1 root root 343 Feb 1 2021 minidlna.xml -rw-r--r-- 1 root root 237 Feb 1 2021 mongodb.xml -rw-r--r-- 1 root root 473 Feb 1 2021 mosh.xml -rw-r--r-- 1 root root 211 Feb 1 2021 mountd.xml -rw-r--r-- 1 root root 296 Feb 1 2021 mqtt-tls.xml -rw-r--r-- 1 root root 287 Feb 1 2021 mqtt.xml -rw-r--r-- 1 root root 170 Feb 1 2021 mssql.xml -rw-r--r-- 1 root root 190 Feb 1 2021 ms-wbt.xml -rw-r--r-- 1 root root 242 Feb 1 2021 murmur.xml -rw-r--r-- 1 root root 171 Feb 1 2021 mysql.xml -rw-r--r-- 1 root root 250 Feb 1 2021 nbd.xml -rw-r--r-- 1 root root 342 Feb 1 2021 nfs3.xml -rw-r--r-- 1 root root 324 Feb 1 2021 nfs.xml -rw-r--r-- 1 root root 293 Feb 1 2021 nmea-0183.xml -rw-r--r-- 1 root root 247 Feb 1 2021 nrpe.xml -rw-r--r-- 1 root root 389 Feb 1 2021 ntp.xml -rw-r--r-- 1 root root 368 Feb 1 2021 nut.xml -rw-r--r-- 1 root root 335 Feb 1 2021 openvpn.xml -rw-r--r-- 1 root root 260 Feb 1 2021 ovirt-imageio.xml -rw-r--r-- 1 root root 343 Feb 1 2021 ovirt-storageconsole.xml -rw-r--r-- 1 root root 235 Feb 1 2021 ovirt-vmconsole.xml -rw-r--r-- 1 root root 1024 Feb 1 2021 plex.xml -rw-r--r-- 1 root root 433 Feb 1 2021 pmcd.xml -rw-r--r-- 1 root root 474 Feb 1 2021 pmproxy.xml -rw-r--r-- 1 root root 544 Feb 1 2021 pmwebapis.xml -rw-r--r-- 1 root root 460 Feb 1 2021 pmwebapi.xml -rw-r--r-- 1 root root 357 Feb 1 2021 pop3s.xml -rw-r--r-- 1 root root 348 Feb 1 2021 pop3.xml -rw-r--r-- 1 root root 181 Feb 1 2021 postgresql.xml -rw-r--r-- 1 root root 509 Feb 1 2021 privoxy.xml -rw-r--r-- 1 root root 213 Feb 1 2021 prometheus.xml -rw-r--r-- 1 root root 261 Feb 1 2021 proxy-dhcp.xml -rw-r--r-- 1 root root 424 Feb 1 2021 ptp.xml -rw-r--r-- 1 root root 414 Feb 1 2021 pulseaudio.xml -rw-r--r-- 1 root root 297 Feb 1 2021 puppetmaster.xml -rw-r--r-- 1 root root 273 Feb 1 2021 quassel.xml -rw-r--r-- 1 root root 520 Feb 1 2021 radius.xml -rw-r--r-- 1 root root 183 Feb 1 2021 rdp.xml -rw-r--r-- 1 root root 212 Feb 1 2021 redis-sentinel.xml -rw-r--r-- 1 root root 268 Feb 1 2021 redis.xml -rw-r--r-- 1 root root 381 Feb 1 2021 RH-Satellite-6-capsule.xml -rw-r--r-- 1 root root 556 Feb 1 2021 RH-Satellite-6.xml -rw-r--r-- 1 root root 214 Feb 1 2021 rpc-bind.xml -rw-r--r-- 1 root root 213 Feb 1 2021 rquotad.xml -rw-r--r-- 1 root root 310 Feb 1 2021 rsh.xml -rw-r--r-- 1 root root 311 Feb 1 2021 rsyncd.xml -rw-r--r-- 1 root root 350 Feb 1 2021 rtsp.xml -rw-r--r-- 1 root root 329 Feb 1 2021 salt-master.xml -rw-r--r-- 1 root root 371 Feb 1 2021 samba-client.xml -rw-r--r-- 1 root root 1298 Feb 1 2021 samba-dc.xml -rw-r--r-- 1 root root 448 Feb 1 2021 samba.xml -rw-r--r-- 1 root root 324 Feb 1 2021 sane.xml -rw-r--r-- 1 root root 283 Feb 1 2021 sips.xml -rw-r--r-- 1 root root 496 Feb 1 2021 sip.xml -rw-r--r-- 1 root root 299 Feb 1 2021 slp.xml -rw-r--r-- 1 root root 231 Feb 1 2021 smtp-submission.xml -rw-r--r-- 1 root root 577 Feb 1 2021 smtps.xml -rw-r--r-- 1 root root 550 Feb 1 2021 smtp.xml -rw-r--r-- 1 root root 308 Feb 1 2021 snmptrap.xml -rw-r--r-- 1 root root 342 Feb 1 2021 snmp.xml -rw-r--r-- 1 root root 405 Feb 1 2021 spideroak-lansync.xml -rw-r--r-- 1 root root 275 Feb 1 2021 spotify-sync.xml -rw-r--r-- 1 root root 173 Feb 1 2021 squid.xml -rw-r--r-- 1 root root 421 Feb 1 2021 ssdp.xml -rw-r--r-- 1 root root 463 Feb 1 2021 ssh.xml -rw-r--r-- 1 root root 631 Feb 1 2021 steam-streaming.xml -rw-r--r-- 1 root root 287 Feb 1 2021 svdrp.xml -rw-r--r-- 1 root root 231 Feb 1 2021 svn.xml -rw-r--r-- 1 root root 297 Feb 1 2021 syncthing-gui.xml -rw-r--r-- 1 root root 311 Feb 1 2021 syncthing.xml -rw-r--r-- 1 root root 496 Feb 1 2021 synergy.xml -rw-r--r-- 1 root root 444 Feb 1 2021 syslog-tls.xml -rw-r--r-- 1 root root 329 Feb 1 2021 syslog.xml -rw-r--r-- 1 root root 393 Feb 1 2021 telnet.xml -rw-r--r-- 1 root root 252 Feb 1 2021 tentacle.xml -rw-r--r-- 1 root root 288 Feb 1 2021 tftp-client.xml -rw-r--r-- 1 root root 424 Feb 1 2021 tftp.xml -rw-r--r-- 1 root root 221 Feb 1 2021 tile38.xml -rw-r--r-- 1 root root 336 Feb 1 2021 tinc.xml -rw-r--r-- 1 root root 771 Feb 1 2021 tor-socks.xml -rw-r--r-- 1 root root 244 Feb 1 2021 transmission-client.xml -rw-r--r-- 1 root root 264 Feb 1 2021 upnp-client.xml -rw-r--r-- 1 root root 593 Feb 1 2021 vdsm.xml -rw-r--r-- 1 root root 475 Feb 1 2021 vnc-server.xml -rw-r--r-- 1 root root 310 Feb 1 2021 wbem-https.xml -rw-r--r-- 1 root root 352 Feb 1 2021 wbem-http.xml -rw-r--r-- 1 root root 323 Feb 1 2021 wsmans.xml -rw-r--r-- 1 root root 316 Feb 1 2021 wsman.xml -rw-r--r-- 1 root root 329 Feb 1 2021 xdmcp.xml -rw-r--r-- 1 root root 509 Feb 1 2021 xmpp-bosh.xml -rw-r--r-- 1 root root 488 Feb 1 2021 xmpp-client.xml -rw-r--r-- 1 root root 264 Feb 1 2021 xmpp-local.xml -rw-r--r-- 1 root root 545 Feb 1 2021 xmpp-server.xml -rw-r--r-- 1 root root 314 Feb 1 2021 zabbix-agent.xml -rw-r--r-- 1 root root 315 Feb 1 2021 zabbix-server.xml /usr/lib/firewalld/zones: total 40 -rw-r--r-- 1 root root 299 Feb 1 2021 block.xml -rw-r--r-- 1 root root 293 Feb 1 2021 dmz.xml -rw-r--r-- 1 root root 291 Feb 1 2021 drop.xml -rw-r--r-- 1 root root 304 Feb 1 2021 external.xml -rw-r--r-- 1 root root 369 Feb 1 2021 home.xml -rw-r--r-- 1 root root 384 Feb 1 2021 internal.xml -rw-r--r-- 1 root root 729 Apr 12 2021 nm-shared.xml -rw-r--r-- 1 root root 315 Feb 1 2021 public.xml -rw-r--r-- 1 root root 162 Feb 1 2021 trusted.xml -rw-r--r-- 1 root root 311 Feb 1 2021 work.xml
Ces fichiers sont au format xml, par exemple :
root@debian11:~# cat /usr/lib/firewalld/zones/home.xml<?xml version="1.0" encoding="utf-8"?> <zone> <short>Home</short> <description>For use in home areas. You mostly trust the other computers on networks to not harm your computer. Only selected incoming connections are accepted.</description> <service name="ssh"/> <service name="mdns"/> <service name="samba-client"/> <service name="dhcpv6-client"/> </zone>
La configuration de firewalld ainsi que les définitions et règles personnalisées se trouvent dans /etc/firewalld :
root@debian11:~# ls -lR /etc/firewalld/ /etc/firewalld/: total 32 -rw-r--r-- 1 root root 2745 Feb 1 2021 firewalld.conf drwxr-xr-x 2 root root 4096 Feb 1 2021 helpers drwxr-xr-x 2 root root 4096 Feb 1 2021 icmptypes drwxr-xr-x 2 root root 4096 Feb 1 2021 ipsets -rw-r--r-- 1 root root 268 Feb 1 2021 lockdown-whitelist.xml drwxr-xr-x 2 root root 4096 Feb 1 2021 policies drwxr-xr-x 2 root root 4096 Feb 1 2021 services drwxr-xr-x 2 root root 4096 Feb 1 2021 zones /etc/firewalld/helpers: total 0 /etc/firewalld/icmptypes: total 0 /etc/firewalld/ipsets: total 0 /etc/firewalld/policies: total 0 /etc/firewalld/services: total 0 /etc/firewalld/zones: total 0
Le fichier de configuration de firewalld est /etc/firewalld/firewalld.conf :
root@debian11:~# cat /etc/firewalld/firewalld.conf # firewalld config file # default zone # The default zone used if an empty zone string is used. # Default: public DefaultZone=public # Clean up on exit # If set to no or false the firewall configuration will not get cleaned up # on exit or stop of firewalld # Default: yes CleanupOnExit=yes # Lockdown # If set to enabled, firewall changes with the D-Bus interface will be limited # to applications that are listed in the lockdown whitelist. # The lockdown whitelist file is lockdown-whitelist.xml # Default: no Lockdown=no # IPv6_rpfilter # Performs a reverse path filter test on a packet for IPv6. If a reply to the # packet would be sent via the same interface that the packet arrived on, the # packet will match and be accepted, otherwise dropped. # The rp_filter for IPv4 is controlled using sysctl. # Default: yes IPv6_rpfilter=yes # IndividualCalls # Do not use combined -restore calls, but individual calls. This increases the # time that is needed to apply changes and to start the daemon, but is good for # debugging. # Default: no IndividualCalls=no # LogDenied # Add logging rules right before reject and drop rules in the INPUT, FORWARD # and OUTPUT chains for the default rules and also final reject and drop rules # in zones. Possible values are: all, unicast, broadcast, multicast and off. # Default: off LogDenied=off # FirewallBackend # Selects the firewall backend implementation. # Choices are: # - nftables (default) # - iptables (iptables, ip6tables, ebtables and ipset) FirewallBackend=nftables # FlushAllOnReload # Flush all runtime rules on a reload. In previous releases some runtime # configuration was retained during a reload, namely; interface to zone # assignment, and direct rules. This was confusing to users. To get the old # behavior set this to "no". # Default: yes FlushAllOnReload=yes # RFC3964_IPv4 # As per RFC 3964, filter IPv6 traffic with 6to4 destination addresses that # correspond to IPv4 addresses that should not be routed over the public # internet. # Defaults to "yes". RFC3964_IPv4=yes # AllowZoneDrifting # Older versions of firewalld had undocumented behavior known as "zone # drifting". This allowed packets to ingress multiple zones - this is a # violation of zone based firewalls. However, some users rely on this behavior # to have a "catch-all" zone, e.g. the default zone. You can enable this if you # desire such behavior. It's disabled by default for security reasons. # Note: If "yes" packets will only drift from source based zones to interface # based zones (including the default zone). Packets never drift from interface # based zones to other interfaces based zones (including the default zone). # Possible values; "yes", "no". Defaults to "no". AllowZoneDrifting=no
1.2 - La Commande firewall-cmd
firewalld s'appuie sur netfilter. Pour cette raison, l'utilisation de firewall-cmd est incompatible avec l'utilisation des commandes iptables et system-config-firewall.
Important - firewall-cmd est le front-end de firewalld en ligne de commande. Il existe aussi la commande firewall-config qui lance un outil de configuration graphique.
Pour obtenir la liste de toutes les zones prédéfinies, utilisez la commande suivante :
root@debian11:~# firewall-cmd --get-zones block dmz drop external home internal nm-shared public trusted work
Pour obtenir la liste de toutes les services prédéfinis, utilisez la commande suivante :
root@debian11:~# firewall-cmd --get-services RH-Satellite-6 RH-Satellite-6-capsule amanda-client amanda-k5-client amqp amqps apcupsd audit bacula bacula-client bb bgp bitcoin bitcoin-rpc bitcoin-testnet bitcoin-testnet-rpc bittorrent-lsd ceph ceph-mon cfengine cockpit collectd condor-collector ctdb dhcp dhcpv6 dhcpv6-client distcc dns dns-over-tls docker-registry docker-swarm dropbox-lansync elasticsearch etcd-client etcd-server finger foreman foreman-proxy freeipa-4 freeipa-ldap freeipa-ldaps freeipa-replication freeipa-trust ftp ganglia-client ganglia-master git grafana gre high-availability http https imap imaps ipp ipp-client ipsec irc ircs iscsi-target isns jenkins kadmin kdeconnect kerberos kibana klogin kpasswd kprop kshell kube-apiserver ldap ldaps libvirt libvirt-tls lightning-network llmnr managesieve matrix mdns memcache minidlna mongodb mosh mountd mqtt mqtt-tls ms-wbt mssql murmur mysql nbd nfs nfs3 nmea-0183 nrpe ntp nut openvpn ovirt-imageio ovirt-storageconsole ovirt-vmconsole plex pmcd pmproxy pmwebapi pmwebapis pop3 pop3s postgresql privoxy prometheus proxy-dhcp ptp pulseaudio puppetmaster quassel radius rdp redis redis-sentinel rpc-bind rquotad rsh rsyncd rtsp salt-master samba samba-client samba-dc sane sip sips slp smtp smtp-submission smtps snmp snmptrap spideroak-lansync spotify-sync squid ssdp ssh steam-streaming svdrp svn syncthing syncthing-gui synergy syslog syslog-tls telnet tentacle tftp tftp-client tile38 tinc tor-socks transmission-client upnp-client vdsm vnc-server wbem-http wbem-https wsman wsmans xdmcp xmpp-bosh xmpp-client xmpp-local xmpp-server zabbix-agent zabbix-server
Pour obtenir la liste de toutes les types ICMP prédéfinis, utilisez la commande suivante :
root@debian11:~# firewall-cmd --get-icmptypes address-unreachable bad-header beyond-scope communication-prohibited destination-unreachable echo-reply echo-request failed-policy fragmentation-needed host-precedence-violation host-prohibited host-redirect host-unknown host-unreachable ip-header-bad neighbour-advertisement neighbour-solicitation network-prohibited network-redirect network-unknown network-unreachable no-route packet-too-big parameter-problem port-unreachable precedence-cutoff protocol-unreachable redirect reject-route required-option-missing router-advertisement router-solicitation source-quench source-route-failed time-exceeded timestamp-reply timestamp-request tos-host-redirect tos-host-unreachable tos-network-redirect tos-network-unreachable ttl-zero-during-reassembly ttl-zero-during-transit unknown-header-type unknown-option
Pour obtenir la liste des zones de la configuration courante, utilisez la commande suivante :
root@debian11:~# firewall-cmd --get-active-zones public interfaces: ens18
Pour obtenir la liste des zones de la configuration courante pour une interface spécifique, utilisez la commande suivante :
root@debian11:~# firewall-cmd --get-zone-of-interface=ens18 public
Pour obtenir la liste des services autorisés pour la zone public, utilisez la commande suivante :
root@debian11:~# firewall-cmd --zone=public --list-services dhcpv6-client ssh
Pour obtenir toute la configuration pour la zone public, utilisez la commande suivante :
root@debian11:~# firewall-cmd --zone=public --list-all public (active) target: default icmp-block-inversion: no interfaces: ens18 sources: services: dhcpv6-client ssh ports: protocols: forward: no masquerade: no forward-ports: source-ports: icmp-blocks: rich rules:
Pour obtenir la liste complète de toutes les zones et leurs configurations, utilisez la commande suivante :
root@debian11:~# firewall-cmd --list-all-zones
block
target: %%REJECT%%
icmp-block-inversion: no
interfaces:
sources:
services:
ports:
protocols:
forward: no
masquerade: no
forward-ports:
source-ports:
icmp-blocks:
rich rules:
dmz
target: default
icmp-block-inversion: no
interfaces:
sources:
services: ssh
ports:
protocols:
forward: no
masquerade: no
forward-ports:
source-ports:
icmp-blocks:
rich rules:
drop
target: DROP
icmp-block-inversion: no
interfaces:
sources:
services:
ports:
protocols:
forward: no
masquerade: no
forward-ports:
source-ports:
icmp-blocks:
rich rules:
external
target: default
icmp-block-inversion: no
interfaces:
sources:
services: ssh
ports:
protocols:
forward: no
masquerade: yes
forward-ports:
source-ports:
icmp-blocks:
rich rules:
home
target: default
icmp-block-inversion: no
interfaces:
sources:
services: dhcpv6-client mdns samba-client ssh
ports:
protocols:
forward: no
masquerade: no
forward-ports:
source-ports:
icmp-blocks:
rich rules:
internal
target: default
icmp-block-inversion: no
interfaces:
sources:
services: dhcpv6-client mdns samba-client ssh
ports:
protocols:
forward: no
masquerade: no
forward-ports:
source-ports:
icmp-blocks:
rich rules:
nm-shared
target: ACCEPT
icmp-block-inversion: no
interfaces:
sources:
services: dhcp dns ssh
ports:
protocols: icmp ipv6-icmp
forward: no
masquerade: no
forward-ports:
source-ports:
icmp-blocks:
rich rules:
rule priority="32767" reject
public (active)
target: default
icmp-block-inversion: no
interfaces: ens18
sources:
services: dhcpv6-client ssh
ports:
protocols:
forward: no
masquerade: no
forward-ports:
source-ports:
icmp-blocks:
rich rules:
trusted
target: ACCEPT
icmp-block-inversion: no
interfaces:
sources:
services:
ports:
protocols:
forward: no
masquerade: no
forward-ports:
source-ports:
icmp-blocks:
rich rules:
work
target: default
icmp-block-inversion: no
interfaces:
sources:
services: dhcpv6-client ssh
ports:
protocols:
forward: no
masquerade: no
forward-ports:
source-ports:
icmp-blocks:
rich rules:
Pour changer la zone par défaut de public à work, utilisez la commande suivante :
root@debian11:~# firewall-cmd --set-default-zone=work success root@debian11:~# firewall-cmd --get-active-zones work interfaces: ens18
Pour ajouter l'interface ip_fixe à la zone work, utilisez la commande suivante :
root@debian11:~# firewall-cmd --zone=work --add-interface=ip_fixe success root@debian11:~# firewall-cmd --get-active-zones work interfaces: ens18 ip_fixe
Pour supprimer l'interface ip_fixe à la zone work, utilisez la commande suivante :
root@debian11:~# firewall-cmd --zone=work --remove-interface=ip_fixe success root@debian11:~# firewall-cmd --get-active-zones work interfaces: ens18
Pour ajouter le service http à la zone work, utilisez la commande suivante :
root@debian11:~# firewall-cmd --zone=work --add-service=http success root@debian11:~# firewall-cmd --zone=work --list-services dhcpv6-client http ssh
Pour supprimer le service http de la zone work, utilisez la commande suivante :
root@debian11:~# firewall-cmd --zone=work --remove-service=http success root@debian11:~# firewall-cmd --zone=work --list-services dhcpv6-client ssh
Pour ajouter un nouveau bloc ICMP, utilisez la commande suivante :
root@debian11:~# firewall-cmd --zone=work --add-icmp-block=echo-reply success root@debian11:~# firewall-cmd --zone=work --list-icmp-blocks echo-reply
Pour supprimer un bloc ICMP, utilisez la commande suivante :
root@debian11:~# firewall-cmd --zone=work --remove-icmp-block=echo-reply success root@debian11:~# firewall-cmd --zone=work --list-icmp-blocks root@debian11:~#
Pour ajouter le port 591/tcp à la zone work, utilisez la commande suivante :
root@debian11:~# firewall-cmd --zone=work --add-port=591/tcp success root@debian11:~# firewall-cmd --zone=work --list-ports 591/tcp
Pour supprimer le port 591/tcp à la zone work, utilisez la commande suivante :
root@debian11:~# firewall-cmd --zone=work --remove-port=591/tcp success root@debian11:~# firewall-cmd --zone=work --list-ports root@debian11:~#
Pour créer un nouveau service, il convient de :
- copier un fichier existant se trouvant dans le répertoire /usr/lib/firewalld/services vers /etc/firewalld/services,
- modifier le fichier,
- recharger la configuration de firewalld,
- vérifier que firewalld voit le nouveau service.
Par exemple :
root@debian11:~# cp /usr/lib/firewalld/services/http.xml /etc/firewalld/services/filemaker.xml root@debian11:~# cat /etc/firewalld/services/filemaker.xml <?xml version="1.0" encoding="utf-8"?> <service> <short>WWW (HTTP)</short> <description>HTTP is the protocol used to serve Web pages. If you plan to make your Web server publicly available, enable this option. This option is not required for viewing pages locally or developing Web pages.</description> <port protocol="tcp" port="80"/> </service> root@debian11:~# vi /etc/firewalld/services/filemaker.xml root@debian11:~# cat /etc/firewalld/services/filemaker.xml <?xml version="1.0" encoding="utf-8"?> <service> <short>FileMakerPro</short> <description>fichier de service firewalld pour FileMaker Pro</description> <port protocol="tcp" port="591"/> </service> root@debian11:~# firewall-cmd --reload success root@debian11:~# firewall-cmd --get-services RH-Satellite-6 RH-Satellite-6-capsule amanda-client amanda-k5-client amqp amqps apcupsd audit bacula bacula-client bb bgp bitcoin bitcoin-rpc bitcoin-testnet bitcoin-testnet-rpc bittorrent-lsd ceph ceph-mon cfengine cockpit collectd condor-collector ctdb dhcp dhcpv6 dhcpv6-client distcc dns dns-over-tls docker-registry docker-swarm dropbox-lansync elasticsearch etcd-client etcd-server filemaker finger foreman foreman-proxy freeipa-4 freeipa-ldap freeipa-ldaps freeipa-replication freeipa-trust ftp ganglia-client ganglia-master git grafana gre high-availability http https imap imaps ipp ipp-client ipsec irc ircs iscsi-target isns jenkins kadmin kdeconnect kerberos kibana klogin kpasswd kprop kshell kube-apiserver ldap ldaps libvirt libvirt-tls lightning-network llmnr managesieve matrix mdns memcache minidlna mongodb mosh mountd mqtt mqtt-tls ms-wbt mssql murmur mysql nbd nfs nfs3 nmea-0183 nrpe ntp nut openvpn ovirt-imageio ovirt-storageconsole ovirt-vmconsole plex pmcd pmproxy pmwebapi pmwebapis pop3 pop3s postgresql privoxy prometheus proxy-dhcp ptp pulseaudio puppetmaster quassel radius rdp redis redis-sentinel rpc-bind rquotad rsh rsyncd rtsp salt-master samba samba-client samba-dc sane sip sips slp smtp smtp-submission smtps snmp snmptrap spideroak-lansync spotify-sync squid ssdp ssh steam-streaming svdrp svn syncthing syncthing-gui synergy syslog syslog-tls telnet tentacle tftp tftp-client tile38 tinc tor-socks transmission-client upnp-client vdsm vnc-server wbem-http wbem-https wsman wsmans xdmcp xmpp-bosh xmpp-client xmpp-local xmpp-server zabbix-agent zabbix-server
1.3 - La Configuration Avancée de firewalld
La configuration de base de firewalld ne permet que la configuration des zones, services, blocs ICMP et les ports non-standard. Cependant, firewalld peut également être configuré avec des Rich Rules ou Règles Riches. Rich Rules ou Règles Riches évaluent des critères pour ensuite entreprendre une action.
Les Critères sont :
- source address=“<adresse_IP>“
- destination address=”<adresse_IP>“,
- rule port port=”<numéro_du_port>“,
- service name=<nom_d'un_sevice_prédéfini>.
Les Actions sont :
- accept,
- reject,
- une Action reject peut être associée avec un message d'erreur spécifique par la clause type=”<type_d'erreur>,
- drop.
Saisissez la commande suivante pour ouvrir le port 80 :
root@debian11:~# firewall-cmd --add-rich-rule='rule port port="80" protocol="tcp" accept' success
Important - Notez que la Rich Rule doit être entourée de caractères '.
Important - Notez que la Rich Rule a créé deux règles, une pour IPv4 et une deuxième pour IPv6. Une règle peut être créée pour IPv4 seul en incluant le Critère family=ipv4. De la même façon, une règle peut être créée pour IPv6 seul en incluant le Critère family=ipv6.
Cette nouvelle règle est écrite en mémoire mais non pas sur disque. Pour l'écrire sur disque dans le fichier zone se trouvant dans /etc/firewalld, il faut ajouter l'option –permanent :
root@debian11:~# firewall-cmd --add-rich-rule='rule port port="80" protocol="tcp" accept' --permanent
success
root@debian11:~# cat /etc/firewalld/zones/work.xml
<?xml version="1.0" encoding="utf-8"?>
<zone>
<short>Work</short>
<description>For use in work areas. You mostly trust the other computers on networks to not harm your computer. Only selected incoming connections are accepted.</description>
<service name="ssh"/>
<service name="dhcpv6-client"/>
<rule>
<port port="80" protocol="tcp"/>
<accept/>
</rule>
</zone>
Important - Attention ! La règle ajoutée avec l'option –permanent n'est pas prise en compte immédiatement mais uniquement au prochain redémmarge. Pour qu'une règle soit appliquée immédiatement et écrite sur disque, il faut saisir la commande deux fois dont une avec l'option –permanent et l'autre sans l'option –permanent.
Pour visualiser cette règle dans la configuration de firewalld, il convient de saisir la commande suivante :
root@debian11:~# firewall-cmd --reload
success
root@debian11:~# firewall-cmd --zone=work --list-all
work (active)
target: default
icmp-block-inversion: no
interfaces: ens18
sources:
services: dhcpv6-client ssh
ports:
protocols:
forward: no
masquerade: no
forward-ports:
source-ports:
icmp-blocks:
rich rules:
rule port port="80" protocol="tcp" accept
Notez que la Rich Rule est créée dans la Zone par Défaut. Il est possible de créer une Rich Rule dans une autre zone en utilisant l'option –zone=<zone> de la commande firewall-cmd :
root@debian11:~# firewall-cmd --zone=public --add-rich-rule='rule port port="80" protocol="tcp" accept'
success
root@debian11:~# firewall-cmd --reload
success
root@debian11:~# firewall-cmd --zone=public --list-all
public
target: default
icmp-block-inversion: no
interfaces:
sources:
services: dhcpv6-client ssh
ports:
protocols:
forward: no
masquerade: no
forward-ports:
source-ports:
icmp-blocks:
rich rules:
root@debian11:~# firewall-cmd --zone=public --add-rich-rule='rule port port="80" protocol="tcp" accept' --permanent
success
root@debian11:~# firewall-cmd --zone=public --list-all
public
target: default
icmp-block-inversion: no
interfaces:
sources:
services: dhcpv6-client ssh
ports:
protocols:
forward: no
masquerade: no
forward-ports:
source-ports:
icmp-blocks:
rich rules:
root@debian11:~# firewall-cmd --reload
success
root@debian11:~# firewall-cmd --zone=public --list-all
public
target: default
icmp-block-inversion: no
interfaces:
sources:
services: dhcpv6-client ssh
ports:
protocols:
forward: no
masquerade: no
forward-ports:
source-ports:
icmp-blocks:
rich rules:
rule port port="80" protocol="tcp" accept
Pour supprimer une Rich Rule, il faut copier la ligne entière la concernant qui se trouve dans la sortie de la commande firewall-cmd –list-all-zones :
root@debian11:~# firewall-cmd --zone=public --remove-rich-rule='rule port port="80" protocol="tcp" accept' success root@debian11:~# firewall-cmd --zone=public --list-all public target: default icmp-block-inversion: no interfaces: sources: services: dhcpv6-client ssh ports: protocols: forward: no masquerade: no forward-ports: source-ports: icmp-blocks: rich rules:
1.4 - Le mode Panic de firewalld
Le mode Panic de firewalld permet de bloquer tout le trafic avec une seule commande. Pour connaître l'état du mode Panic, utilisez la commande suivante :
root@debian8:~# firewall-cmd --query-panic no
Pour activer le mode Panic, il convient de saisir la commande suivante :
# firewall-cmd --panic-on
Pour désactiver le mode Panic, il convient de saisir la commande suivante :
# firewall-cmd --panic-off
Copyright © 2025 Hugh Norris.