Cette section s'intéresse à la création de la machine k3s_passrelle.
Cet élément de l'architecture est la passerelle par défaut du réseau des machines virtuelles. Elle porte également les services :
Cette machine virtuelle fonctionne sur Ubuntu 24.04-3 LTS Server.
guillaume@rocket:~/Lab_K3S$ virt-install \
--name k3s_passerelle \
--memory 4096 \
--vcpus 2 \
--cpu host \
--disk path=/home/guillaume/Lab_K3S/VM/k3s_passerelle_systeme.qcow2,size=20,format=qcow2 \
--cdrom /home/guillaume/ISO/ubuntu-24.04.3-live-server-amd64.iso \
--network network=default,model=virtio \
--network network=lan_interne_infra,model=virtio \
--os-variant ubuntu24.04 \
--graphics spice \
--boot useserial=on \
--noautoconsole
Début d’installation…
Création du domaine… | 0 B 00:00:00
Domain is still running. Installation may be in progress.
You can reconnect to the console to complete the installation process.
guillaume@rocket:~/Téléchargements$ ssh guillaume@192.168.122.119
The authenticity of host '192.168.122.119 (192.168.122.119)' can't be established.
ED25519 key fingerprint is SHA256:f8Lx+R7vjQSEPIEess1aJSJWXpd1hEgtgdatIDFExEk.
This key is not known by any other names.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added '192.168.122.119' (ED25519) to the list of known hosts.
guillaume@192.168.122.119's password:
Welcome to Ubuntu 24.04.3 LTS (GNU/Linux 6.8.0-90-generic x86_64)
* Documentation: https://help.ubuntu.com
* Management: https://landscape.canonical.com
* Support: https://ubuntu.com/pro
System information as of dim. 04 janv. 2026 17:35:24 UTC
System load: 0.1 Processes: 139
Usage of /: 25.6% of 9.75GB Users logged in: 0
Memory usage: 5% IPv4 address for enp1s0: 192.168.122.119
Swap usage: 0%
La maintenance de sécurité étendue pour Applications n'est pas activée.
59 mises à jour peuvent être appliquées immédiatement.
Pour afficher ces mises à jour supplémentaires, exécuter : apt list --upgradable
Activez ESM Apps pour recevoir des futures mises à jour de sécurité supplémentaires.
Visitez https://ubuntu.com/esm ou executez : sudo pro status
To run a command as administrator (user "root"), use "sudo <command>".
See "man sudo_root" for details.
guillaume@k3s-passerelle:~$
root@k3s-passerelle:/home/guillaume# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host noprefixroute
valid_lft forever preferred_lft forever
2: enp1s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
link/ether 52:54:00:df:ac:83 brd ff:ff:ff:ff:ff:ff
inet 192.168.122.119/24 metric 100 brd 192.168.122.255 scope global dynamic enp1s0
valid_lft 3384sec preferred_lft 3384sec
inet6 fe80::5054:ff:fedf:ac83/64 scope link
valid_lft forever preferred_lft forever
3: enp2s0: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN group default qlen 1000
link/ether 52:54:00:35:43:6c brd ff:ff:ff:ff:ff:ff
/etc/netplan/50-cloud-init.yaml:root@k3s-passerelle:/home/guillaume# vim /etc/netplan/50-cloud-init.yaml
network:
version: 2
ethernets:
enp1s0:
dhcp4: true
enp2s0:
dhcp4: false
addresses:
- 192.168.50.254/24
root@k3s-passerelle:/home/guillaume# netplan generate
root@k3s-passerelle:/home/guillaume# netplan apply
root@k3s-passerelle:/home/guillaume# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host noprefixroute
valid_lft forever preferred_lft forever
2: enp1s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
link/ether 52:54:00:df:ac:83 brd ff:ff:ff:ff:ff:ff
inet 192.168.122.119/24 metric 100 brd 192.168.122.255 scope global dynamic enp1s0
valid_lft 3599sec preferred_lft 3599sec
inet6 fe80::5054:ff:fedf:ac83/64 scope link
valid_lft forever preferred_lft forever
3: enp2s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
link/ether 52:54:00:35:43:6c brd ff:ff:ff:ff:ff:ff
inet 192.168.50.254/24 brd 192.168.50.255 scope global enp2s0
valid_lft forever preferred_lft forever
inet6 fe80::5054:ff:fe35:436c/64 scope link
valid_lft forever preferred_lft forever
Les interfaces de la passerelle sont maintenant configurées.
/opt/passelle:root@k3s-passerelle:~# mkdir /opt/passerelle
root@k3s-passerelle:~# vim /opt/passerelle/gw.sh
#!/usr/bin/env bash
set -euo pipefail
# =========================
# Gateway EV1 / EduPF
# Ubuntu Server 24.04
# LAN: enp2s0 (192.168.50.0/24, GW=192.168.50.254)
# WAN: enp1s0 (DHCP via libvirt default, 192.168.122.0/24)
# =========================
WAN_IF="enp1s0"
LAN_IF="enp2s0"
LAN_NET="192.168.50.0/24"
log() { echo "[gateway] $*"; }
log "Enabling IPv4 forwarding..."
cat >/etc/sysctl.d/99-edupf-gateway.conf <<EOF
net.ipv4.ip_forward=1
EOF
sysctl --system >/dev/null
log "Ensuring nftables is available..."
command -v nft >/dev/null 2>&1 || { echo "nft not found. Install: sudo apt install -y nftables"; exit 1; }
log "Applying nftables rules (NAT + forwarding)..."
# Table dédiée pour éviter de casser d'autres règles éventuelles
# (on la recrée à chaque fois => idempotent)
nft delete table ip edupf 2>/dev/null || true
nft add table ip edupf
# NAT
nft add chain ip edupf postrouting '{ type nat hook postrouting priority 100 ; policy accept ; }'
nft add rule ip edupf postrouting oifname "$WAN_IF" ip saddr $LAN_NET masquerade
# Filtrage / forwarding
nft add chain ip edupf forward '{ type filter hook forward priority 0 ; policy drop ; }'
# Autoriser les connexions établies/related (retour du trafic)
nft add rule ip edupf forward ct state established,related accept
# Autoriser LAN -> WAN
nft add rule ip edupf forward iifname "$LAN_IF" oifname "$WAN_IF" ip saddr $LAN_NET accept
# (Optionnel) Autoriser ping de diagnostic
# nft add rule ip edupf forward ip protocol icmp accept
log "Done."
root@k3s-passerelle:~# chmod +x /opt/passerelle/gw.sh
root@k3s-passerelle:~# vim /etc/systemd/system/gateway.service
[Unit]
Description=K3S Lab Gateway (routing + NAT)
After=network-online.target
Wants=network-online.target
[Service]
Type=oneshot
ExecStart=/opt/passerelle/gw.sh
RemainAfterExit=yes
[Install]
WantedBy=multi-user.target
root@k3s-passerelle:~# systemctl daemon-reload
root@k3s-passerelle:~# systemctl enable --now gateway.service
Created symlink /etc/systemd/system/multi-user.target.wants/gateway.service → /etc/systemd/system/gateway.service.
root@k3s-passerelle:~# systemctl status gateway.service
● gateway.service - K3S Lab Gateway (routing + NAT)
Loaded: loaded (/etc/systemd/system/gateway.service; enabled; preset: enabled)
Active: active (exited) since Sun 2026-01-04 17:53:59 UTC; 36s ago
Process: 1798 ExecStart=/opt/passerelle/gw.sh (code=exited, status=0/SUCCESS)
Main PID: 1798 (code=exited, status=0/SUCCESS)
CPU: 34ms
janv. 04 17:53:59 k3s-passerelle systemd[1]: Starting gateway.service - K3S Lab Gateway (routing + NAT)...
janv. 04 17:53:59 k3s-passerelle gw.sh[1798]: [gateway] Enabling IPv4 forwarding...
janv. 04 17:53:59 k3s-passerelle gw.sh[1798]: [gateway] Ensuring nftables is available...
janv. 04 17:53:59 k3s-passerelle gw.sh[1798]: [gateway] Applying nftables rules (NAT + forwarding)...
janv. 04 17:53:59 k3s-passerelle gw.sh[1798]: [gateway] Done.
janv. 04 17:53:59 k3s-passerelle systemd[1]: Finished gateway.service - K3S Lab Gateway (routing + NAT).
La passerelle est maintenant active.
root@k3s-passerelle:~# apt install -y bind9 bind9-utils dnsutils
bind9
Fournit le démon principal named, responsable :
bind9-utils
Fournit les outils d’administration et de validation :
named-checkconf : validation de la configuration globalenamed-checkzone : validation syntaxique et logique des zones DNSdnsutils
Fournit les outils clients de diagnostic DNS :
dignslookupAprès l'installation les services DNS sont automatiquement activés et démarrés :
root@k3s-passerelle:~# systemctl status bind9 --no-pager
● named.service - BIND Domain Name Server
Loaded: loaded (/usr/lib/systemd/system/named.service; enabled; preset: enabled)
Active: active (running) since Sun 2026-01-04 18:03:02 UTC; 2min 57s ago
Docs: man:named(8)
Main PID: 2172 (named)
Status: "running"
Tasks: 8 (limit: 4605)
Memory: 24.4M (peak: 24.8M)
CPU: 75ms
CGroup: /system.slice/named.service
└─2172 /usr/sbin/named -f -u bind
/etc/bind/named.conf.options :root@k3s-passerelle:~# vim /etc/bind/named.conf.options
options {
directory "/var/cache/bind";
listen-on { 127.0.0.1; 192.168.50.254; };
listen-on-v6 { none; };
allow-query { localhost; 192.168.50.0/24; };
recursion yes;
allow-recursion { localhost; 192.168.50.0/24; };
forwarders { 192.168.2.20; };
forward only;
dnssec-validation no;
version "not disclosed";
};
directory
Répertoire utilisé par BIND pour stocker :
listen-on
Limite les interfaces IPv4 d’écoute :
127.0.0.1 : tests locaux192.168.50.254 : clients du LANlisten-on-v6
Désactive explicitement IPv6, non utilisé dans l’architecture actuelle.
allow-query
Autorise les requêtes DNS uniquement depuis :
recursion / allow-recursion
Autorise la résolution récursive uniquement pour le LAN.
Cette restriction est fondamentale pour éviter un open resolver.
forwarders
Serveur DNS amont vers lequel sont relayées les requêtes non locales.
forward only
Interdit toute tentative de résolution directe sur Internet.
dnssec-validation
Active la validation DNSSEC pour les domaines externes: mettre auto
Ici on met à no pour éviter les erreurs
version
Masque la version exacte de BIND (bonne pratique de sécurité).
/etc/bind/named.conf.local :root@k3s-passerelle:~# vim /etc/bind/named.conf.local
zone "labk3s.ev1" {
type master;
file "/etc/bind/zones/db.labk3s.ev1";
};
Il s"agit ici de déclarer le fichier qui contiendra les enregistrements de la zone.
root@k3s-passerelle:~# mkdir -p /etc/bind/zones
/etc/bind/zones/db.labk3s.ev1 :root@k3s-passerelle:~# vim /etc/bind/zones/db.labk3s.ev1
$TTL 1h
@ IN SOA ns1.labk3s.ev1. admin.labk3s.ev1. (
2026011501 ; Serial (YYYYMMDDNN)
1h ; Refresh
15m ; Retry
7d ; Expire
1h ; Negative Cache TTL
)
@ IN NS ns1.labk3s.ev1.
ns1 IN A 192.168.50.254
gw IN A 192.168.50.254
kube-01 IN A 192.168.50.11
kube-02 IN A 192.168.50.12
kube-03 IN A 192.168.50.13
root@k3s-passerelle:~# systemctl restart bind9
$TTL
Durée de mise en cache par défaut des enregistrements.
SOA (Start Of Authority)
Définit :
Serial
Doit être incrémenté à chaque modification du fichier.
NS
Serveur DNS autoritatif de la zone.
A
Association nom → adresse IPv4.
Selon les besoins futurs :
CNAME : alias DNSMX : serveurs de messagerieTXT : SPF, DKIM, informations diversesPTR : résolution inverse (zone reverse)SRV : services (LDAP, Kerberos, etc.)root@k3s-passerelle:~# named-checkconf
root@k3s-passerelle:~# named-checkzone edulibre.ev1 /etc/bind/zones/db.labk3s.ev1
zone edulibre.ev1/IN: loaded serial 2026011501
OK
root@k3s-passerelle:~# dig @127.0.0.1 ns1.labk3s.ev1 +short
192.168.50.254
root@k3s-passerelle:~# apt install -y isc-dhcp-server
/etc/default/isc-dhcp-server :root@k3s-passerelle:~# vim /etc/default/isc-dhcp-server
INTERFACESv4="enp2s0"
/etc/dhcp/dhcpd.conf :root@k3s-passerelle:~# vim /etc/dhcp/dhcpd.conf
# Durée de bail
default-lease-time 600;
max-lease-time 7200;
# Le serveur est autoritatif sur ce réseau
authoritative;
# DNS
option domain-name "labk3s.ev1";
option domain-name-servers 192.168.50.254;
# Déclarations pour le LAN
subnet 192.168.50.0 netmask 255.255.255.0 {
range 192.168.50.100 192.168.50.200;
option routers 192.168.50.254;
option broadcast-address 192.168.50.255;
}
root@k3s-passerelle:~# systemctl enable isc-dhcp-server
root@k3s-passerelle:~# systemctl restart isc-dhcp-server
root@k3s-passerelle:~# systemctl status isc-dhcp-server
● isc-dhcp-server.service - ISC DHCP IPv4 server
Loaded: loaded (/usr/lib/systemd/system/isc-dhcp-server.service; enabled; >
Active: active (running) since Thu 2026-01-15 20:12:55 UTC; 22s ago
Docs: man:dhcpd(8)
Main PID: 1717 (dhcpd)
Tasks: 1 (limit: 4605)
Memory: 3.7M (peak: 4.0M)
CPU: 15ms
CGroup: /system.slice/isc-dhcp-server.service
└─1717 dhcpd -user dhcpd -group dhcpd -f -4 -pf /run/dhcp-server/d>
root@k3s-passerelle:~# dhcpd -t
La passerelle est installée et fonctionnelle. Lorsque les noeuds Kubernetes seront installés nous ajouterons l'enregistrement wilcard dans le DNS.