← Todos os guias
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.
Este guia foi elaborado a partir da documentação oficial do WireGuard VPN server on Ubuntu, ligada acima — verifique sempre lá os nomes exatos dos pacotes/versões antes de executar estes comandos num servidor de produção, uma vez que as versões da distribuição e do projeto mudam com o tempo.
1Install WireGuard
sudo apt updatesudo apt install -y wireguard2Generate server and client key pairs
wg genkey | sudo tee /etc/wireguard/server_private.key | wg pubkey | sudo tee /etc/wireguard/server_public.keywg genkey | tee client_private.key | wg pubkey | tee client_public.key3Create 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=1sudo wg-quick up wg0sudo systemctl enable wg-quick@wg0A 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.
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.