MirrorNest
← Tous les guides

WireGuard VPN server on Ubuntu

A modern, extremely fast VPN protocol built directly into the Linux kernel — set up your own WireGuard server for remote access to your home network without relying on a third-party VPN provider.

Système : Ubuntu 22.04 LTS / 24.04 LTSVPNnetworkingself-hostedSite officiel ↗Documentation officielle ↗
Ce guide est élaboré à partir de la documentation officielle de WireGuard VPN server on Ubuntu, dont le lien figure ci-dessus — vérifiez toujours les noms exacts des paquets/versions avant d'exécuter ces commandes sur un serveur de production, car les versions de la distribution et du projet évoluent avec le temps.
  1. 1Install WireGuard

    sudo apt update
    sudo apt install -y wireguard
  2. 2Generate server and client key pairs

    wg genkey | sudo tee /etc/wireguard/server_private.key | wg pubkey | sudo tee /etc/wireguard/server_public.key
    wg genkey | tee client_private.key | wg pubkey | tee client_public.key
  3. 3Create the server config

    Create /etc/wireguard/wg0.conf defining the server's own tunnel IP, listen port, and one [Peer] section per client, then enable IP forwarding and start the interface.

    sudo sysctl -w net.ipv4.ip_forward=1
    sudo wg-quick up wg0
    sudo systemctl enable wg-quick@wg0

    A full example wg0.conf (server + client sections, NAT/forwarding rules) is in WireGuard's own quickstart guide -- getting the AllowedIPs and PostUp/PostDown iptables rules right is the part most worth copying exactly rather than guessing.

  4. 4Configure the client and connect

    Create a matching config on the client device (phone/laptop) with the server's public key and endpoint, then activate the tunnel.