Linux & Serveurs

WireGuard — Installer un VPN en 10 minutes

WireGuard — Installer un VPN en 10 minutes

WireGuard est révolutionnaire : 4000 lignes de code contre 100 000+ pour OpenVPN.

Installation

sudo apt update && sudo apt install -y wireguard
echo "net.ipv4.ip_forward = 1" | sudo tee /etc/sysctl.d/99-wireguard.conf
sudo sysctl -p /etc/sysctl.d/99-wireguard.conf

Génération des clés

wg genkey | sudo tee /etc/wireguard/server_private.key | \
    wg pubkey | sudo tee /etc/wireguard/server_public.key
sudo chmod 600 /etc/wireguard/server_private.key

Configuration du serveur

[Interface]
Address = 10.0.0.1/24
ListenPort = 51820
PrivateKey = <SERVER_PRIVATE_KEY>

PostUp = iptables -A FORWARD -i %i -j ACCEPT; iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
PostDown = iptables -D FORWARD -i %i -j ACCEPT; iptables -t nat -D POSTROUTING -o eth0 -j MASQUERADE

[Peer]
PublicKey = <CLIENT_PUBLIC_KEY>
AllowedIPs = 10.0.0.2/32

Configuration du client

[Interface]
Address = 10.0.0.2/32
PrivateKey = <CLIENT_PRIVATE_KEY>
DNS = 1.1.1.1

[Peer]
PublicKey = <SERVER_PUBLIC_KEY>
AllowedIPs = 0.0.0.0/0, ::/0
Endpoint = VOTRE_IP:51820
PersistentKeepalive = 25

Démarrage

sudo ufw allow 51820/udp
sudo wg-quick up wg0
sudo systemctl enable wg-quick@wg0
sudo wg show

QR Code pour mobile

sudo apt install qrencode
qrencode -t ansiutf8 < /tmp/client.conf

Scannez avec l'app WireGuard sur iOS/Android — connexion instantanée !

// Commentaires (1)

Connectez-vous pour laisser un commentaire.

tony amprou
tony amprou 1 month ago
test