MirrorNest
← Все руководства

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.

Система: Ubuntu 22.04 LTS / 24.04 LTSVPNnetworkingself-hostedОфициальный сайт ↗Официальная документация ↗
Это руководство составлено на основе официальной документации WireGuard VPN server on Ubuntu, ссылка на которую есть выше — всегда сверяйте точные названия пакетов/версий там перед запуском этих команд на рабочем сервере, так как версии дистрибутива и проекта со временем меняются.
  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.