« Wireguard ipv6 GUA » : différence entre les versions
Aucun résumé des modifications |
Aucun résumé des modifications |
||
| Ligne 1 : | Ligne 1 : | ||
= | Source: https://blog.miyuru.lk/setup-wireguard-with-global-ipv6/ | ||
Configurer WireGuard avec une IPv6 unicast globale.<br /> | |||
Un simple tunnel VPN à double pile avec prise en charge IPv6 globale.<br /> | |||
WireGuard devient populaire auprès des utilisateurs de Linux en tant que VPN car il est intégré au noyau Linux, ce qui offre de meilleures performances | |||
Cependant, de nombreux tutoriels et scripts qui configurent WireGuard le font avec NATing de l'adresse IPv6 et donnent à l'utilisateur une adresse IPv6 locale de lien. Cela amène le système d'exploitation à préférer IPv4 à IPv6.<br /><br /> | |||
⚠️ Wireguard sur Raspberry Pi OS (bookworm)<br /><br /> | |||
Ajout d'un sous-réseau avec /80.<br /> | |||
Possiblité d'utiliser des sous-réseaux plus petits avec un sous-réseau approprié.<br /> | |||
<pre> | |||
Original Block - 2000:xxx:xxx:x11:328e::/80 | |||
For the VPN Endpoint - 2000:xxx:xxx:x11:328e::123/128 | |||
For the VPN Clients - 2000:xxx:xxx:x11:328e:ffff::/96 | |||
VPN Endpoint port - 51820 | |||
pihole network interface - eth0 | |||
Gateway 2000:xxx:xxx:x11::1 | |||
</pre> | |||
Nous donnons également une seule adresse IPv6 pour chaque client, mais vous pouvez également attribuer un sous-réseau par client.<br /> | |||
Pour une configuration IPv6 vraiment appropriée, vous pouvez attribuer à chaque client un sous-réseau /64 et configurer SLAAC.<br /> | |||
== Ajouter les IPv6 sur eth0 == | |||
Avec NetworkManager | |||
<pre>sudo nmtui</pre> | |||
CONFIGURATION IPv6<br /> | |||
Ajouter les adresses:<br /> | |||
<pre> | |||
2000:xxx:xxx:x11:328e::123/128 | |||
2000:xxx:xxx:x11:328e:ffff::/96 | |||
</pre> | |||
<pre> | |||
sudo service NetworkManager restart | |||
</pre> | |||
== Activer l'IP forwarding == | |||
Assurez-vous d'ajouter les éléments suivants à /etc/sysctl.d/99-pivpn.conf | |||
<pre> | |||
net.ipv4.ip_forward = 1 | |||
net.ipv6.conf.all.forwarding = 1 | |||
net.ipv6.conf.ens5.accept_ra = 2 | |||
</pre> | |||
puis, <pre>sudo sysctl --system</pre> pour appliquer les modifications<br /> | |||
== Configuration de l'interface wg0 == | |||
# Dans les règles IPv4, nous effectuons un NAT pour l'adresse IPv4.<br /> | |||
<pre> | |||
PostUp = iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE; | |||
PostDown = iptables -t nat -D POSTROUTING -o eth0 -j MASQUERADE; | |||
</pre> | |||
# Dans les règles IPv6, nous ajoutons une règle pour transférer le trafic vers l'interface Internet.<br /> | |||
<pre> | |||
PostUp = iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE;ip6tables -A FORWARD -i eth0 -o wg0 -j ACCEPT; ip6tables -A FORWARD -i wg0 -j ACCEPT; | |||
PostDown = iptables -t nat -D POSTROUTING -o eth0 -j MASQUERADE;ip6tables -D FORWARD -i eth0 -o wg0 -j ACCEPT; ip6tables -D FORWARD -i wg0 -j ACCEPT; | |||
</pre> | |||
# Version nftables avant l'ipv6 | |||
<pre> | |||
PostUp = nft add table ip wireguard;nft add chain ip wireguard wireguard_chain {type nat hook postrouting priority srcnat\; policy accept\;};nft add rule ip wireguard wireguard_chain counter packets 0 bytes 0 masquerade;nft add table ip6 wireguard;nft add chain ip6 wireguard wireguard_chain {type nat hook postrouting priority srcnat\; policy accept\;};nft add rule ip6 wireguard wireguard_chain counter packets 0 bytes 0 masquerade; | |||
PostDown = nft delete table ip wireguard; nft delete table ip6 wireguard | |||
</pre> | |||
# Version nftables avec l'ipv6 | |||
<pre> | <pre> | ||
PostUp = nft add table ip wireguard;nft add chain ip wireguard wireguard_chain {type nat hook postrouting priority srcnat\; policy accept\;};nft add rule ip wireguard wireguard_chain counter packets 0 bytes 0 masquerade; nft add table ip6 wireguard;nft add chain ip6 wireguard wireguard_chain {type nat hook postrouting priority srcnat\; policy accept\;};nft add rule ip6 wireguard wireguard_chain counter packets 0 bytes 0 masquerade;nft add chain ip6 wireguard FORWARD { type filter hook forward priority filter\; };nft add rule ip6 wireguard FORWARD iifname "eth0" oifname "wg0" ct state related,established counter accept;nft add rule ip6 wireguard FORWARD iifname "wg0" counter accept; | |||
PostDown = nft delete table ip wireguard; nft delete table ip6 wireguard | |||
</pre> | </pre> | ||
Pour l'IP client, nous utilisons les premières IP de la plage désignée. Dans IPv6, vous pouvez autoriser un grand sous-réseau ici et cela permettra au client de se déplacer dans différentes IP du sous-réseau. | |||
AllowedIPs = 10.66.66.2, 2000:xxx:xxx:x11:328e:ffff::2/128 | |||
Donc dans <pre>/etc/wireguard/wg0.conf</pre> | |||
# | <pre> | ||
# | [Interface] | ||
Address = 10.66.66.1/24, fd42:42:42::1/64 | |||
ListenPort = 51820 | |||
PrivateKey = | |||
PostUp = nft add table ip wireguard;nft add chain ip wireguard wireguard_chain {type nat hook postrouting priority srcnat\; policy accept\;};nft add rule ip wireguard wireguard_chain counter pac> | |||
PostDown = nft delete table ip wireguard; nft delete table ip6 wireguard | |||
... | |||
### Client 1 | |||
[Peer] | |||
PublicKey = | |||
#PresharedKey = | |||
AllowedIPs = 10.66.66.2, 2000:xxx:xxx:x11:328e:ffff::2/128 | |||
</pre> | |||
== Configuration du client == | |||
Ici, nous autorisons une seule adresse IPv6. Si la configuration du serveur autorise un grand sous-réseau, nous pouvons la modifier en conséquence.<br /> | |||
<pre> | |||
Adresse = 10.66.66.2, 2000:xxx:xxx:x11:328e:ffff::2/128 | |||
</pre> | |||
Configuration complète. Enregistrée dans /etc/wireguard/client1.conf | |||
<pre> | <pre> | ||
[Interface] | |||
PrivateKey = | |||
Address = 10.66.66.2, 2000:xxx:xxx:x11:328e:ffff::2/128 | |||
DNS = 2606:4700:4700::1001 | |||
[Peer] | |||
PublicKey = | |||
#PresharedKey = | |||
AllowedIPs = 0.0.0.0/0, ::/0 | |||
Endpoint = [2000:xxx:xxx:xxx:x11::123]:51820 | |||
</pre> | |||
== Redémarrer le tunel == | |||
<pre> | |||
sudo wg-quick down wg0 | |||
sudo wg-quick up wg0 | |||
</pre> | |||
--- | |||
== Notes: == | |||
# Traduire les régles iptables en nftables | |||
<pre> | |||
ip6tables-translate -A FORWARD -i eth0 -o wg0 -j ACCEPT | |||
ip6tables-translate -A FORWARD -i wg0 -j ACCEPT | |||
=> | |||
nft add rule ip6 wireguard wireguard_forward iifname eth0 oifname wg0 counter accept; | |||
nft add rule ip6 filter chain forward iifname "eth0" oifname "wg0" counter accept; | |||
nft add chain ip6 wireguard wireguard_chain {forward iifname "wg0" counter accept\;}; | |||
</pre> | |||
=== Adapter et tester les règles === | |||
<pre> | |||
# | sudo nft add chain ip6 wireguard FORWARD { type filter hook forward priority filter\; } | ||
sudo nft add rule ip6 wireguard FORWARD iifname "eth0" oifname "wg0" ct state related,established counter accept; | |||
sudo nft add rule ip6 wireguard FORWARD iifname "wg0" counter accept | |||
</pre> | |||
# Pour effacer les règles: | |||
<pre> | |||
sudo wg-quick down wg0 | |||
sudo wg-quick up wg0 | |||
</pre> | |||
# Pour contrôler les règles: | |||
<pre> | |||
sudo nft list ruleset | |||
</pre> | |||
# Résultat | |||
<pre> | |||
table inet filter { | |||
chain input { | |||
type filter hook input priority filter; policy accept; | |||
} | |||
chain forward { | |||
type filter hook forward priority filter; policy accept; | |||
} | |||
chain output { | |||
type filter hook output priority filter; policy accept; | |||
} | |||
} | |||
table ip wireguard { | |||
chain wireguard_chain { | |||
type nat hook postrouting priority srcnat; policy accept; | |||
counter packets 4640 bytes 317839 masquerade | |||
} | |||
} | |||
table ip6 wireguard { | |||
chain wireguard_chain { | |||
type nat hook postrouting priority srcnat; policy accept; | |||
counter packets 1350 bytes 145915 masquerade | |||
} | |||
chain FORWARD { | |||
type filter hook forward priority filter; policy accept; | |||
iifname "eth0" oifname "wg0" ct state established,related counter packets 13820 bytes 9978553 accept | |||
iifname "wg0" counter packets 10031 bytes 3057534 accept | |||
} | |||
} | |||
</pre> | </pre> | ||