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.