Ceci est une ancienne révision du document !


Version : 2024.01

Dernière mise-à-jour : 2024/10/22 07:23

LRF606 - Gestion de Netfilter et de Firewalld

Contenu du Module

  • LRF606 - Gestion de Netfilter et de 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 par firewalld
        • La Configuration de Base de firewalld
        • La Commande firewall-cmd
        • La Configuration Avancée de firewalld
        • 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 renvoie 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 la dite 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 des gros paquets ICMP vers la cible.

Le Contre-Mesure

Le contre-mesure est principalement l'utilisation d'un pare-feu.

Le Pare-feu Netfilter/iptables

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.

IPTABLES peut être configuré soit par des outils tels shorewall, soit en utilisant des lignes de commandes ou un script. Dans ce dernier cas, la ligne prend la forme:

# IPTABLES --action CHAINE --option1 --option2

Les actions sont:

Action Abréviation Déscription
- -append -A Ajouter une règle à la fin de la chaîne spécifiée
- -delete -D Supprimer une règle en spécifiant son numéro ou la règle à supprimer
- -replace -R Permet de remplacer la règle spécifée par son numéro
- -insert -I Permet d'insérer une règle à l'endroit spécifié
- -list -L Permet d'afficher des règles
- -flush -F Permet de vider toutes les règles d'une chaîne

Les options sont:

Option Abréviation Déscription
- -protocol -p Permet de spécifier un protocol - tcp, udp, icmp, all
- -source -s Permet de spécifier une adresse source
- -destination -d Permet de spécifier une adresse de destination
- -in-interface -i Permet de spécifier une interface réseau d'entrée
- -out-interface -o Permet de spécifier une interface réseau de sortie
- -fragment -f Permet de ne spécifier que les paquets fragmentés
- -source-port -sport Permet de spécifier un port source ou une plage de ports source
- -destination-port -dport Permet de spécifier un port de destination ou une plage de ports de destination
- -tcp-flags s/o Permet de spécifier un flag TCP à matcher - SYN, ACK, FIN, RST, URG, PSH, ALL, NONE
- -icmp-type s/o Permet de spécifier un type de paquet ICMP
- -mac-source s/o Permet de spécifier une adresse MAC

Les options spécifiques à NET sont:

- -to-destination s/o Permet de spécifier l'adresse de destination d'une translation
- -to-source s/o Permet spécifier l'adresse source d'une translation

Les options spécifiques aux LOGS sont:

- -log-level s/o Permet de spécifier le niveau de logs
- -log-prefix s/o Permet de spécifier un préfix pour les logs

L'option spécifique au STATEFUL est:

- -state s/o Permet de spécifier l'état du paquet à vérifier

Ce dernier cas fait référence au STATEFUL. Le STATEFUL est la capacité du par-feu à enregistrer dans une table spécifique, l'état des différentes connexions. Cette table s'appelle une table d'état. Le principe du fonctionnement de STATEFUL est simple, à savoir, si le paquet entrant appartient à une communication déjà établie, celui-ci n'est pas vérifié.

Il existe 4 états:

  • NEW
    • Le paquet concerne une nouvelle connexion et contient donc un flag SYN à 1
  • ESTABLISHED
    • Le paquet concerne une connexion déjà établie. Le paquet ne doit contenir ni flag SYN à 1, ni flag FIN à 1
  • RELATED
    • Le paquet est d'une connexion qui présente une relation avec une autre connexion
  • INVALID
    • La paquet provient d'une connexion anormale.

LAB #1 - La Configuration par firewalld

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.

Le service firewalld doit toujours être lancé :

[root@centos8 ~]# systemctl status firewalld.service
● firewalld.service - firewalld - dynamic firewall daemon
   Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled; vendor preset: enabled)
   Active: active (running) since Tue 2024-10-01 12:13:55 CEST; 1h 43min ago
     Docs: man:firewalld(1)
 Main PID: 1079 (firewalld)
    Tasks: 2 (limit: 100949)
   Memory: 32.7M
   CGroup: /system.slice/firewalld.service
           └─1079 /usr/libexec/platform-python -s /usr/sbin/firewalld --nofork --nopid

Oct 01 12:13:53 centos8.ittraining.loc systemd[1]: Starting firewalld - dynamic firewall daemon...
Oct 01 12:13:55 centos8.ittraining.loc systemd[1]: Started firewalld - dynamic firewall daemon.
Oct 01 12:13:56 centos8.ittraining.loc firewalld[1079]: WARNING: AllowZoneDrifting is enabled. This is considered an insecure configuration option. It will be removed in a future release.
[q]

La Configuration de Base de firewalld

La configuration par défaut de firewalld se trouve dans /usr/lib/firewalld :

[root@centos8 ~]# ls -l /usr/lib/firewalld/
total 16
drwxr-xr-x. 2 root root  224 Mar  6  2022 helpers
drwxr-xr-x. 2 root root 4096 Mar  6  2022 icmptypes
drwxr-xr-x. 2 root root   20 Mar  6  2022 ipsets
drwxr-xr-x. 2 root root   33 Mar  6  2022 policies
drwxr-xr-x. 2 root root 8192 Mar  6  2022 services
drwxr-xr-x. 2 root root  203 Mar  6  2022 zones

[root@centos8 ~]# ls -l /usr/lib/firewalld/zones
total 44
-rw-r--r--. 1 root root 299 Aug  9  2021 block.xml
-rw-r--r--. 1 root root 293 Aug  9  2021 dmz.xml
-rw-r--r--. 1 root root 291 Aug  9  2021 drop.xml
-rw-r--r--. 1 root root 304 Aug  9  2021 external.xml
-rw-r--r--. 1 root root 397 Aug  9  2021 home.xml
-rw-r--r--. 1 root root 412 Aug  9  2021 internal.xml
-rw-r--r--. 1 root root 809 Nov 26  2019 libvirt.xml
-rw-r--r--. 1 root root 729 Aug 18  2021 nm-shared.xml
-rw-r--r--. 1 root root 343 Aug  9  2021 public.xml
-rw-r--r--. 1 root root 162 Aug  9  2021 trusted.xml
-rw-r--r--. 1 root root 339 Aug  9  2021 work.xml

[root@centos8 ~]# ls -l /usr/lib/firewalld/services
total 704
-rw-r--r--. 1 root root  399 Aug  9  2021 amanda-client.xml
-rw-r--r--. 1 root root  427 Aug  9  2021 amanda-k5-client.xml
-rw-r--r--. 1 root root  283 Aug  9  2021 amqps.xml
-rw-r--r--. 1 root root  273 Aug  9  2021 amqp.xml
-rw-r--r--. 1 root root  285 Aug  9  2021 apcupsd.xml
-rw-r--r--. 1 root root  301 Aug  9  2021 audit.xml
-rw-r--r--. 1 root root  320 Aug  9  2021 bacula-client.xml
-rw-r--r--. 1 root root  346 Aug  9  2021 bacula.xml
-rw-r--r--. 1 root root  429 Aug  9  2021 bb.xml
-rw-r--r--. 1 root root  339 Aug  9  2021 bgp.xml
-rw-r--r--. 1 root root  275 Aug  9  2021 bitcoin-rpc.xml
-rw-r--r--. 1 root root  307 Aug  9  2021 bitcoin-testnet-rpc.xml
-rw-r--r--. 1 root root  281 Aug  9  2021 bitcoin-testnet.xml
-rw-r--r--. 1 root root  244 Aug  9  2021 bitcoin.xml
-rw-r--r--. 1 root root  410 Aug  9  2021 bittorrent-lsd.xml
-rw-r--r--. 1 root root  294 Aug  9  2021 ceph-mon.xml
-rw-r--r--. 1 root root  329 Aug  9  2021 ceph.xml
-rw-r--r--. 1 root root  168 Aug  9  2021 cfengine.xml
-rw-r--r--. 1 root root  211 Aug  9  2021 cockpit.xml
-rw-r--r--. 1 root root  296 Aug  9  2021 collectd.xml
-rw-r--r--. 1 root root  260 Aug  9  2021 condor-collector.xml
-rw-r--r--. 1 root root  296 Aug  9  2021 ctdb.xml
-rw-r--r--. 1 root root  305 Aug  9  2021 dhcpv6-client.xml
-rw-r--r--. 1 root root  234 Aug  9  2021 dhcpv6.xml
-rw-r--r--. 1 root root  227 Aug  9  2021 dhcp.xml
-rw-r--r--. 1 root root  205 Aug  9  2021 distcc.xml
-rw-r--r--. 1 root root  318 Aug  9  2021 dns-over-tls.xml
-rw-r--r--. 1 root root  346 Aug  9  2021 dns.xml
-rw-r--r--. 1 root root  374 Aug  9  2021 docker-registry.xml
-rw-r--r--. 1 root root  391 Aug  9  2021 docker-swarm.xml
-rw-r--r--. 1 root root  228 Aug  9  2021 dropbox-lansync.xml
-rw-r--r--. 1 root root  338 Aug  9  2021 elasticsearch.xml
-rw-r--r--. 1 root root  304 Aug  9  2021 etcd-client.xml
-rw-r--r--. 1 root root  304 Aug  9  2021 etcd-server.xml
-rw-r--r--. 1 root root  224 Aug  9  2021 finger.xml
-rw-r--r--. 1 root root  270 Aug  9  2021 foreman-proxy.xml
-rw-r--r--. 1 root root  408 Aug  9  2021 foreman.xml
-rw-r--r--. 1 root root  709 Aug  9  2021 freeipa-4.xml
-rw-r--r--. 1 root root  489 Aug  9  2021 freeipa-ldaps.xml
-rw-r--r--. 1 root root  488 Aug  9  2021 freeipa-ldap.xml
-rw-r--r--. 1 root root  242 Aug  9  2021 freeipa-replication.xml
-rw-r--r--. 1 root root  657 Aug  9  2021 freeipa-trust.xml
-rw-r--r--. 1 root root  361 Aug  9  2021 ftp.xml
-rw-r--r--. 1 root root  292 Aug  9  2021 galera.xml
-rw-r--r--. 1 root root  184 Aug  9  2021 ganglia-client.xml
-rw-r--r--. 1 root root  176 Aug  9  2021 ganglia-master.xml
-rw-r--r--. 1 root root  212 Aug  9  2021 git.xml
-rw-r--r--. 1 root root  218 Aug  9  2021 grafana.xml
-rw-r--r--. 1 root root  119 Aug  9  2021 gre.xml
-rw-r--r--. 1 root root  608 Aug  9  2021 high-availability.xml
-rw-r--r--. 1 root root  448 Aug  9  2021 https.xml
-rw-r--r--. 1 root root  353 Aug  9  2021 http.xml
-rw-r--r--. 1 root root  372 Aug  9  2021 imaps.xml
-rw-r--r--. 1 root root  327 Aug  9  2021 imap.xml
-rw-r--r--. 1 root root  454 Aug  9  2021 ipp-client.xml
-rw-r--r--. 1 root root  427 Aug  9  2021 ipp.xml
-rw-r--r--. 1 root root  894 Aug  9  2021 ipsec.xml
-rw-r--r--. 1 root root  255 Aug  9  2021 ircs.xml
-rw-r--r--. 1 root root  247 Aug  9  2021 irc.xml
-rw-r--r--. 1 root root  264 Aug  9  2021 iscsi-target.xml
-rw-r--r--. 1 root root  358 Aug  9  2021 isns.xml
-rw-r--r--. 1 root root  213 Aug  9  2021 jenkins.xml
-rw-r--r--. 1 root root  182 Aug  9  2021 kadmin.xml
-rw-r--r--. 1 root root  272 Aug  9  2021 kdeconnect.xml
-rw-r--r--. 1 root root  233 Aug  9  2021 kerberos.xml
-rw-r--r--. 1 root root  384 Aug  9  2021 kibana.xml
-rw-r--r--. 1 root root  249 Aug  9  2021 klogin.xml
-rw-r--r--. 1 root root  221 Aug  9  2021 kpasswd.xml
-rw-r--r--. 1 root root  182 Aug  9  2021 kprop.xml
-rw-r--r--. 1 root root  242 Aug  9  2021 kshell.xml
-rw-r--r--. 1 root root  308 Aug  9  2021 kube-apiserver.xml
-rw-r--r--. 1 root root  232 Aug  9  2021 ldaps.xml
-rw-r--r--. 1 root root  199 Aug  9  2021 ldap.xml
-rw-r--r--. 1 root root  385 Aug  9  2021 libvirt-tls.xml
-rw-r--r--. 1 root root  389 Aug  9  2021 libvirt.xml
-rw-r--r--. 1 root root  269 Aug  9  2021 lightning-network.xml
-rw-r--r--. 1 root root  324 Aug  9  2021 llmnr.xml
-rw-r--r--. 1 root root  349 Aug  9  2021 managesieve.xml
-rw-r--r--. 1 root root  432 Aug  9  2021 matrix.xml
-rw-r--r--. 1 root root  424 Aug  9  2021 mdns.xml
-rw-r--r--. 1 root root  245 Aug  9  2021 memcache.xml
-rw-r--r--. 1 root root  343 Aug  9  2021 minidlna.xml
-rw-r--r--. 1 root root  237 Aug  9  2021 mongodb.xml
-rw-r--r--. 1 root root  473 Aug  9  2021 mosh.xml
-rw-r--r--. 1 root root  211 Aug  9  2021 mountd.xml
-rw-r--r--. 1 root root  296 Aug  9  2021 mqtt-tls.xml
-rw-r--r--. 1 root root  287 Aug  9  2021 mqtt.xml
-rw-r--r--. 1 root root  170 Aug  9  2021 mssql.xml
-rw-r--r--. 1 root root  190 Aug  9  2021 ms-wbt.xml
-rw-r--r--. 1 root root  242 Aug  9  2021 murmur.xml
-rw-r--r--. 1 root root  171 Aug  9  2021 mysql.xml
-rw-r--r--. 1 root root  250 Aug  9  2021 nbd.xml
-rw-r--r--. 1 root root  342 Aug  9  2021 nfs3.xml
-rw-r--r--. 1 root root  324 Aug  9  2021 nfs.xml
-rw-r--r--. 1 root root  293 Aug  9  2021 nmea-0183.xml
-rw-r--r--. 1 root root  247 Aug  9  2021 nrpe.xml
-rw-r--r--. 1 root root  389 Aug  9  2021 ntp.xml
-rw-r--r--. 1 root root  368 Aug  9  2021 nut.xml
-rw-r--r--. 1 root root  335 Aug  9  2021 openvpn.xml
-rw-r--r--. 1 root root  260 Aug  9  2021 ovirt-imageio.xml
-rw-r--r--. 1 root root  343 Aug  9  2021 ovirt-storageconsole.xml
-rw-r--r--. 1 root root  235 Aug  9  2021 ovirt-vmconsole.xml
-rw-r--r--. 1 root root 1024 Aug  9  2021 plex.xml
-rw-r--r--. 1 root root  433 Aug  9  2021 pmcd.xml
-rw-r--r--. 1 root root  474 Aug  9  2021 pmproxy.xml
-rw-r--r--. 1 root root  544 Aug  9  2021 pmwebapis.xml
-rw-r--r--. 1 root root  460 Aug  9  2021 pmwebapi.xml
-rw-r--r--. 1 root root  357 Aug  9  2021 pop3s.xml
-rw-r--r--. 1 root root  348 Aug  9  2021 pop3.xml
-rw-r--r--. 1 root root  181 Aug  9  2021 postgresql.xml
-rw-r--r--. 1 root root  509 Aug  9  2021 privoxy.xml
-rw-r--r--. 1 root root  213 Aug  9  2021 prometheus.xml
-rw-r--r--. 1 root root  261 Aug  9  2021 proxy-dhcp.xml
-rw-r--r--. 1 root root  424 Aug  9  2021 ptp.xml
-rw-r--r--. 1 root root  414 Aug  9  2021 pulseaudio.xml
-rw-r--r--. 1 root root  297 Aug  9  2021 puppetmaster.xml
-rw-r--r--. 1 root root  273 Aug  9  2021 quassel.xml
-rw-r--r--. 1 root root  520 Aug  9  2021 radius.xml
-rw-r--r--. 1 root root  183 Aug  9  2021 rdp.xml
-rw-r--r--. 1 root root  212 Aug  9  2021 redis-sentinel.xml
-rw-r--r--. 1 root root  268 Aug  9  2021 redis.xml
-rw-r--r--. 1 root root  381 Aug  9  2021 RH-Satellite-6-capsule.xml
-rw-r--r--. 1 root root  556 Aug  9  2021 RH-Satellite-6.xml
-rw-r--r--. 1 root root  214 Aug  9  2021 rpc-bind.xml
-rw-r--r--. 1 root root  213 Aug  9  2021 rquotad.xml
-rw-r--r--. 1 root root  310 Aug  9  2021 rsh.xml
-rw-r--r--. 1 root root  311 Aug  9  2021 rsyncd.xml
-rw-r--r--. 1 root root  350 Aug  9  2021 rtsp.xml
-rw-r--r--. 1 root root  329 Aug  9  2021 salt-master.xml
-rw-r--r--. 1 root root  371 Aug  9  2021 samba-client.xml
-rw-r--r--. 1 root root 1298 Aug  9  2021 samba-dc.xml
-rw-r--r--. 1 root root  448 Aug  9  2021 samba.xml
-rw-r--r--. 1 root root  324 Aug  9  2021 sane.xml
-rw-r--r--. 1 root root  283 Aug  9  2021 sips.xml
-rw-r--r--. 1 root root  496 Aug  9  2021 sip.xml
-rw-r--r--. 1 root root  299 Aug  9  2021 slp.xml
-rw-r--r--. 1 root root  231 Aug  9  2021 smtp-submission.xml
-rw-r--r--. 1 root root  577 Aug  9  2021 smtps.xml
-rw-r--r--. 1 root root  550 Aug  9  2021 smtp.xml
-rw-r--r--. 1 root root  308 Aug  9  2021 snmptrap.xml
-rw-r--r--. 1 root root  342 Aug  9  2021 snmp.xml
-rw-r--r--. 1 root root  405 Aug  9  2021 spideroak-lansync.xml
-rw-r--r--. 1 root root  275 Aug  9  2021 spotify-sync.xml
-rw-r--r--. 1 root root  173 Aug  9  2021 squid.xml
-rw-r--r--. 1 root root  421 Aug  9  2021 ssdp.xml
-rw-r--r--. 1 root root  463 Aug  9  2021 ssh.xml
-rw-r--r--. 1 root root  631 Aug  9  2021 steam-streaming.xml
-rw-r--r--. 1 root root  287 Aug  9  2021 svdrp.xml
-rw-r--r--. 1 root root  231 Aug  9  2021 svn.xml
-rw-r--r--. 1 root root  297 Aug  9  2021 syncthing-gui.xml
-rw-r--r--. 1 root root  311 Aug  9  2021 syncthing.xml
-rw-r--r--. 1 root root  496 Aug  9  2021 synergy.xml
-rw-r--r--. 1 root root  444 Aug  9  2021 syslog-tls.xml
-rw-r--r--. 1 root root  329 Aug  9  2021 syslog.xml
-rw-r--r--. 1 root root  393 Aug  9  2021 telnet.xml
-rw-r--r--. 1 root root  252 Aug  9  2021 tentacle.xml
-rw-r--r--. 1 root root  288 Aug  9  2021 tftp-client.xml
-rw-r--r--. 1 root root  424 Aug  9  2021 tftp.xml
-rw-r--r--. 1 root root  221 Aug  9  2021 tile38.xml
-rw-r--r--. 1 root root  336 Aug  9  2021 tinc.xml
-rw-r--r--. 1 root root  771 Aug  9  2021 tor-socks.xml
-rw-r--r--. 1 root root  244 Aug  9  2021 transmission-client.xml
-rw-r--r--. 1 root root  264 Aug  9  2021 upnp-client.xml
-rw-r--r--. 1 root root  593 Aug  9  2021 vdsm.xml
-rw-r--r--. 1 root root  475 Aug  9  2021 vnc-server.xml
-rw-r--r--. 1 root root  310 Aug  9  2021 wbem-https.xml
-rw-r--r--. 1 root root  352 Aug  9  2021 wbem-http.xml
-rw-r--r--. 1 root root  323 Aug  9  2021 wsmans.xml
-rw-r--r--. 1 root root  316 Aug  9  2021 wsman.xml
-rw-r--r--. 1 root root  329 Aug  9  2021 xdmcp.xml
-rw-r--r--. 1 root root  509 Aug  9  2021 xmpp-bosh.xml
-rw-r--r--. 1 root root  488 Aug  9  2021 xmpp-client.xml
-rw-r--r--. 1 root root  264 Aug  9  2021 xmpp-local.xml
-rw-r--r--. 1 root root  545 Aug  9  2021 xmpp-server.xml
-rw-r--r--. 1 root root  314 Aug  9  2021 zabbix-agent.xml
-rw-r--r--. 1 root root  315 Aug  9  2021 zabbix-server.xml

[root@centos8 ~]# ls -l /usr/lib/firewalld/icmptypes/
total 180
-rw-r--r--. 1 root root 385 Aug  9  2021 address-unreachable.xml
-rw-r--r--. 1 root root 258 Aug  9  2021 bad-header.xml
-rw-r--r--. 1 root root 294 Aug  9  2021 beyond-scope.xml
-rw-r--r--. 1 root root 279 Aug  9  2021 communication-prohibited.xml
-rw-r--r--. 1 root root 222 Aug  9  2021 destination-unreachable.xml
-rw-r--r--. 1 root root 173 Aug  9  2021 echo-reply.xml
-rw-r--r--. 1 root root 210 Aug  9  2021 echo-request.xml
-rw-r--r--. 1 root root 261 Aug  9  2021 failed-policy.xml
-rw-r--r--. 1 root root 280 Aug  9  2021 fragmentation-needed.xml
-rw-r--r--. 1 root root 266 Aug  9  2021 host-precedence-violation.xml
-rw-r--r--. 1 root root 257 Aug  9  2021 host-prohibited.xml
-rw-r--r--. 1 root root 242 Aug  9  2021 host-redirect.xml
-rw-r--r--. 1 root root 239 Aug  9  2021 host-unknown.xml
-rw-r--r--. 1 root root 247 Aug  9  2021 host-unreachable.xml
-rw-r--r--. 1 root root 229 Aug  9  2021 ip-header-bad.xml
-rw-r--r--. 1 root root 355 Aug  9  2021 neighbour-advertisement.xml
-rw-r--r--. 1 root root 457 Aug  9  2021 neighbour-solicitation.xml
-rw-r--r--. 1 root root 250 Aug  9  2021 network-prohibited.xml
-rw-r--r--. 1 root root 248 Aug  9  2021 network-redirect.xml
-rw-r--r--. 1 root root 239 Aug  9  2021 network-unknown.xml
-rw-r--r--. 1 root root 247 Aug  9  2021 network-unreachable.xml
-rw-r--r--. 1 root root 239 Aug  9  2021 no-route.xml
-rw-r--r--. 1 root root 328 Aug  9  2021 packet-too-big.xml
-rw-r--r--. 1 root root 225 Aug  9  2021 parameter-problem.xml
-rw-r--r--. 1 root root 233 Aug  9  2021 port-unreachable.xml
-rw-r--r--. 1 root root 256 Aug  9  2021 precedence-cutoff.xml
-rw-r--r--. 1 root root 249 Aug  9  2021 protocol-unreachable.xml
-rw-r--r--. 1 root root 185 Aug  9  2021 redirect.xml
-rw-r--r--. 1 root root 244 Aug  9  2021 reject-route.xml
-rw-r--r--. 1 root root 241 Aug  9  2021 required-option-missing.xml
-rw-r--r--. 1 root root 227 Aug  9  2021 router-advertisement.xml
-rw-r--r--. 1 root root 223 Aug  9  2021 router-solicitation.xml
-rw-r--r--. 1 root root 248 Aug  9  2021 source-quench.xml
-rw-r--r--. 1 root root 236 Aug  9  2021 source-route-failed.xml
-rw-r--r--. 1 root root 253 Aug  9  2021 time-exceeded.xml
-rw-r--r--. 1 root root 233 Aug  9  2021 timestamp-reply.xml
-rw-r--r--. 1 root root 228 Aug  9  2021 timestamp-request.xml
-rw-r--r--. 1 root root 258 Aug  9  2021 tos-host-redirect.xml
-rw-r--r--. 1 root root 257 Aug  9  2021 tos-host-unreachable.xml
-rw-r--r--. 1 root root 272 Aug  9  2021 tos-network-redirect.xml
-rw-r--r--. 1 root root 269 Aug  9  2021 tos-network-unreachable.xml
-rw-r--r--. 1 root root 293 Aug  9  2021 ttl-zero-during-reassembly.xml
-rw-r--r--. 1 root root 256 Aug  9  2021 ttl-zero-during-transit.xml
-rw-r--r--. 1 root root 259 Aug  9  2021 unknown-header-type.xml
-rw-r--r--. 1 root root 249 Aug  9  2021 unknown-option.xml

Ces fichiers sont au format xml, par exemple :

[root@centos8 ~]# 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"/>
  <service name="cockpit"/>
</zone>

La configuration de firewalld ainsi que les définitions et règles personnalisées se trouvent dans /etc/firewalld :

[root@centos8 ~]# ls -l /etc/firewalld/
total 8
-rw-r--r--. 1 root root 2840 Aug  9  2021 firewalld.conf
drwxr-x---. 2 root root    6 Aug  9  2021 helpers
drwxr-x---. 2 root root    6 Aug  9  2021 icmptypes
drwxr-x---. 2 root root    6 Aug  9  2021 ipsets
-rw-r--r--. 1 root root  283 Aug  9  2021 lockdown-whitelist.xml
drwxr-x---. 2 root root    6 Aug  9  2021 policies
drwxr-x---. 2 root root    6 Aug  9  2021 services
drwxr-x---. 2 root root   46 Aug  9  2021 zones

[root@centos8 ~]# ls -l /etc/firewalld/zones/
total 8
-rw-r--r--. 1 root root 380 Jun 16  2021 public.xml
-rw-r--r--. 1 root root 343 Jun 16  2021 public.xml.old

[root@centos8 ~]# ls -l /etc/firewalld/services/
total 0

[root@centos8 ~]# ls -l /etc/firewalld/icmptypes/
total 0

Le fichier de configuration de firewalld est /etc/firewalld/firewalld.conf :

[root@centos8 ~]# 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.
# Note: This feature has a performance impact. See man page FIREWALLD.CONF(5)
# for details.
# 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 "yes".
AllowZoneDrifting=yes

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 outi de configuration graphique.

Pour obtenir la liste de toutes les zones prédéfinies, utilisez la commande suivante :

[root@centos8 ~]# firewall-cmd --get-zones
block dmz drop external home internal libvirt nm-shared public trusted work

Pour obtenir la liste de toutes les services prédéfinis, utilisez la commande suivante :

[root@centos8 ~]# 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 galera 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@centos8 ~]# 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@centos8 ~]# firewall-cmd --get-active-zones
libvirt
  interfaces: virbr0
public
  interfaces: ens18

Pour obtenir la liste des zones de la configuration courante pour une interface spécifique, utilisez la commande suivante :

[root@centos8 ~]# 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@centos8 ~]# firewall-cmd --zone=public --list-services
cockpit dhcpv6-client ssh

Pour obtenir toute la configuration pour la zone public, utilisez la commande suivante :

[root@centos8 ~]# firewall-cmd --get-active-zones
libvirt
  interfaces: virbr0
public
  interfaces: ens18
[root@centos8 ~]# firewall-cmd --get-zone-of-interface=ens18
public
[root@centos8 ~]# firewall-cmd --zone=public --list-services
cockpit dhcpv6-client ssh
[root@centos8 ~]# firewall-cmd --zone=public --list-all
public (active)
  target: default
  icmp-block-inversion: no
  interfaces: ens18
  sources: 
  services: cockpit dhcpv6-client ssh
  ports: 5901/tcp
  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@centos8 ~]# firewall-cmd --zone=public --list-all
public (active)
  target: default
  icmp-block-inversion: no
  interfaces: ens18
  sources: 
  services: cockpit dhcpv6-client ssh
  ports: 5901/tcp
  protocols: 
  forward: no
  masquerade: no
  forward-ports: 
  source-ports: 
  icmp-blocks: 
  rich rules: 
[root@centos8 ~]# 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: cockpit 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: cockpit dhcpv6-client mdns samba-client ssh
  ports: 
  protocols: 
  forward: no
  masquerade: no
  forward-ports: 
  source-ports: 
  icmp-blocks: 
  rich rules: 

libvirt (active)
  target: ACCEPT
  icmp-block-inversion: no
  interfaces: virbr0
  sources: 
  services: dhcp dhcpv6 dns ssh tftp
  ports: 
  protocols: icmp ipv6-icmp
  forward: no
  masquerade: no
  forward-ports: 
  source-ports: 
  icmp-blocks: 
  rich rules: 
        rule priority="32767" reject

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: cockpit dhcpv6-client ssh
  ports: 5901/tcp
  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: cockpit 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@centos8 ~]# firewall-cmd --set-default-zone=work
success

[root@centos8 ~]# firewall-cmd --get-active-zones
libvirt
  interfaces: virbr0
work
  interfaces: ens18

Pour ajouter l'interface ip_fixe à la zone work, utilisez la commande suivante :

[root@centos8 ~]# firewall-cmd --zone=work --add-interface=ip_fixe
success

[root@centos8 ~]# firewall-cmd --get-active-zones
libvirt
  interfaces: virbr0
work
  interfaces: ens18 ip_fixe

Pour supprimer l'interface ip_fixe à la zone work, utilisez la commande suivante :

[root@centos8 ~]# firewall-cmd --zone=work --remove-interface=ip_fixe
success

[root@centos8 ~]# firewall-cmd --get-active-zones
libvirt
  interfaces: virbr0
work
  interfaces: ens18

Pour ajouter le service http à la zone work, utilisez la commande suivante :

[root@centos8 ~]# firewall-cmd --zone=work --add-service=http
success

[root@centos8 ~]# firewall-cmd --zone=work --list-services
cockpit dhcpv6-client http ssh

Pour supprimer le service http de la zone work, utilisez la commande suivante :

[root@centos8 ~]# firewall-cmd --zone=work --remove-service=http
success

[root@centos8 ~]# firewall-cmd --zone=work --list-services
cockpit dhcpv6-client ssh

Pour ajouter un nouveau bloc ICMP, utilisez la commande suivante :

[root@centos8 ~]# firewall-cmd --zone=work --add-icmp-block=echo-reply
success

[root@centos8 ~]# firewall-cmd --zone=work --list-icmp-blocks
echo-reply

Pour supprimer un bloc ICMP, utilisez la commande suivante :

[root@centos8 ~]# firewall-cmd --zone=work --remove-icmp-block=echo-reply
success

[root@centos8 ~]# firewall-cmd --zone=work --list-icmp-blocks

[root@centos8 ~]#

Pour ajouter le port 591/tcp à la zone work, utilisez la commande suivante :

[root@centos8 ~]# firewall-cmd --zone=work --add-port=591/tcp
success

[root@centos8 ~]# firewall-cmd --zone=work --list-ports
591/tcp

Pour supprimer le port 591/tcp à la zone work, utilisez la commande suivante :

[root@centos8 ~]# firewall-cmd --zone=work --remove-port=591/tcp
success

[root@centos8 ~]# firewall-cmd --zone=work --list-ports

[root@centos8 ~]#

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@centos8 ~]# cp /usr/lib/firewalld/services/http.xml /etc/firewalld/services/filemaker.xml

[root@centos8 ~]# vi /etc/firewalld/services/filemaker.xml

[root@centos8 ~]# 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@centos8 ~]# firewall-cmd --reload
success

[root@centos8 ~]# 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 galera 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

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@centos8 ~]# 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@centos8 ~]# firewall-cmd --add-rich-rule='rule port port="80" protocol="tcp" accept' --permanent
success

[root@centos8 ~]# 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"/>
  <service name="cockpit"/>
  <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 imédiatement mais uniquement au prochain redémmarge. Pour qu'une règle soit appliquée immédiatement et être écrite sur disque, il faut saisir la commande deux fois dont une avec l'option –permanent et l'autre sans l'option –permanent.

Redémarrez le service firewalld :

[root@centos8 ~]# systemctl restart firewalld.service

Pour visualiser cette règle dans la configuration de firewalld, il convient de saisir la commande suivante :

[root@centos8 ~]# firewall-cmd --zone=work --list-all
work (active)
  target: default
  icmp-block-inversion: no
  interfaces: ens18
  sources: 
  services: cockpit 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@centos8 ~]# firewall-cmd --zone=public --add-rich-rule='rule port port="80" protocol="tcp" accept'
success

[root@centos8 ~]# firewall-cmd --zone=public --list-all
public
  target: default
  icmp-block-inversion: no
  interfaces: 
  sources: 
  services: cockpit dhcpv6-client ssh
  ports: 5901/tcp
  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@centos8 ~]# firewall-cmd --zone=public --remove-rich-rule='rule port port="80" protocol="tcp" accept'
success

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@centos8 ~]# 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 © 2024 Hugh Norris.

Menu