How to set up a WireGuard VPN server on Ubuntu
WireGuard creates an encrypted tunnel between a remote device and an Ubuntu server, giving the device a private route into a home or small-office network. It is fast, lightweight, and supported natively by current Linux kernels. A server can also let managed laptops and phones reach local services without exposing those services directly to the internet.
Many Australian households cannot simply forward a VPN port on their broadband router. Telstra and Optus connections, particularly those delivered over FTTN or some mobile fixed-wireless plans, commonly place the router behind carrier-grade NAT, so inbound packets never reach WireGuard. A VPS with a public IPv4 address avoids that obstacle and gives the tunnel a predictable endpoint.
The build below uses Ubuntu 24.04 LTS, systemd, wg-quick, and uncomplicated firewall rules. It covers a server, a first Linux client, full-tunnel and split-tunnel choices, and routine checks. The configuration is useful for family travel, temporary access to development machines, and privacy on public Wi-Fi, while users remain responsible for obeying network and content rules.
Choose a suitable Ubuntu host
A VPS is usually the simplest choice for a home user because it runs independently of the ISP router and stays online while the household connection changes. Choose an Ubuntu 24.04 LTS instance with one virtual CPU, 512 MB of memory, and a 10 GB disk. A Sydney, Melbourne, Brisbane, or Perth region reduces latency for local users, while Australian providers commonly show prices in AUD including GST.
Before ordering, confirm that the instance receives a dedicated public IPv4 address and supports an inbound UDP rule. Some entry-level plans offer only IPv6 or place customers behind shared addressing, which will not suit the endpoint shown here. A small plan handles a few users, but compare current data allowances and Australian pricing instead of relying on headline bandwidth alone.
If you prefer the existing router, confirm that its firmware supports WireGuard and that its displayed WAN address is publicly reachable. A dynamic residential address can work with a reliable DDNS hostname, but CGNAT still blocks it. Running on a router saves power and can cover televisions and phones automatically, while a VPS is easier to isolate and recover. If the VPS is managed from a multi-screen Ubuntu workstation, the UbuntuNext guide to mixed-resolution Ubuntu displays explains how to arrange a separate monitoring console.
Install WireGuard and prepare forwarding
Start with SSH access using a key pair rather than exposing password login. On a fresh server, update the packages and install WireGuard together with the packet-filtering tools needed for NAT:
sudo apt update
sudo apt full-upgrade -y
sudo apt install -y wireguard iptables
A major kernel update can make a reboot necessary, so reconnect before continuing. The WireGuard package supplies wg and wg-quick; the latter reads the configuration file and manages the interface, routes, and firewall hooks. Keep the server updated, but avoid unattended upgrades during the first setup if a reboot would interrupt the session.
WireGuard needs IPv4 packet forwarding so routed client traffic can leave through the server’s public interface. Make the setting persistent:
sudo tee /etc/sysctl.d/99-wireguard-forward.conf >/dev/null <<'EOF'
net.ipv4.ip_forward = 1
EOF
sudo sysctl --system
Confirm that the output includes net.ipv4.ip_forward = 1. Next, record the public-facing interface name with ip -4 route show default | awk '{print $5; exit}'. Use the resulting name, such as ens3, instead of the example below.
Generate keys and build the server configuration
WireGuard peers authenticate with public keys. Generate a separate pair for the server and for the first client, with restrictive permissions on the private files:
sudo install -d -m 700 /etc/wireguard
cd /etc/wireguard
sudo sh -c 'umask 077; wg genkey | tee server-private.key | wg pubkey > server-public.key; wg genkey | tee laptop-private.key | wg pubkey > laptop-public.key'
sudo cat server-public.key
sudo cat laptop-public.key
The server private key stays on the server. Copy the laptop private key to the client through a secure channel, then securely delete its temporary server-side copy. Never send a private key through ordinary chat or email. Public keys are safe to distribute and must match exactly when peers are paired.
Create the server configuration and replace every placeholder:
sudo nano /etc/wireguard/wg0.conf
[Interface]
Address = 10.66.0.1/24
ListenPort = 51820
PrivateKey = SERVER_PRIVATE_KEY
PostUp = iptables -A FORWARD -i %i -j ACCEPT
PostUp = iptables -A FORWARD -o %i -j ACCEPT
PostUp = iptables -t nat -A POSTROUTING -s 10.66.0.0/24 -o ens3 -j MASQUERADE
PostDown = iptables -D FORWARD -i %i -j ACCEPT
PostDown = iptables -D FORWARD -o %i -j ACCEPT
PostDown = iptables -t nat -D POSTROUTING -s 10.66.0.0/24 -o ens3 -j MASQUERADE
Replace ens3 with the interface name found earlier. Change 10.66.0.0/24 if it overlaps the home LAN, since both networks must have distinct routes. The forwarding rules permit traffic through the tunnel, while masquerading gives internet-bound clients a source address to which the VPS can reply.
Protect and start the file:
sudo chmod 600 /etc/wireguard/wg0.conf
sudo systemctl enable --now wg-quick@wg0
sudo wg show
wg show should list wg0, the server public key, and UDP port 51820. A handshake will remain absent until a client connects. If you edit wg0.conf, restart the unit rather than creating a second interface.
Open the port and secure traffic
WireGuard normally listens on UDP 51820, so allow that port in the VPS provider’s security group and in the host firewall. The cloud rule must permit UDP rather than TCP. On Ubuntu, the following UFW setup also opens SSH and permits forwarding between the tunnel and public interface:
sudo ufw allow 22/tcp
sudo ufw allow 51820/udp
sudo ufw route allow in on wg0 out on ens3
sudo ufw route allow in on ens3 out on wg0
sudo ufw enable
sudo ufw status verbose
Replace 22/tcp if SSH uses a different port, and replace ens3 with the actual interface. If UFW already has a custom policy, add equivalent rules instead of enabling a new policy blindly. The VPS security group and Ubuntu firewall serve different layers, so both must permit the incoming UDP traffic.
Check the three layers separately. The service should be active, the interface should have 10.66.0.1, and NAT should contain a masquerading rule for 10.66.0.0/24:
sudo systemctl is-active wg-quick@wg0
ip -brief address show wg0
sudo iptables -t nat -S POSTROUTING
Expected values are active, the tunnel address, and a POSTROUTING rule containing 10.66.0.0/24 and MASQUERADE. Forwarding remains disabled if the sysctl value is not 1.
Connections that time out usually indicate a blocked UDP path, a security-group omission, or an incorrect endpoint. Residential CGNAT cannot be fixed by changing the WireGuard port. Some hotel and mobile networks also block arbitrary UDP traffic. On a supported home router, forward the chosen UDP port to the WireGuard host and verify that its WAN address is public.
Connect clients and extend access
On the Ubuntu client, install the same package, create /etc/wireguard/laptop.conf, and add its private key, assigned tunnel address, and the server’s public key:
sudo apt install -y wireguard resolvconf
sudo nano /etc/wireguard/laptop.conf
[Interface]
PrivateKey = LAPTOP_PRIVATE_KEY
Address = 10.66.0.2/32
DNS = 1.1.1.1, 1.0.0.1
[Peer]
PublicKey = SERVER_PUBLIC_KEY
Endpoint = 203.0.113.10:51820
AllowedIPs = 0.0.0.0/0
PersistentKeepalive = 25
Replace the example endpoint with the VPS address. This example creates a full IPv4 tunnel. For split tunnelling, replace AllowedIPs with 10.66.0.0/24 and add the home LAN prefix if the server routes it. DNS queries then follow the normal route unless their addresses are deliberately included. If wg-quick cannot apply DNS, remove the DNS line and configure resolvers through NetworkManager.
The server must authorise that client with a peer block containing the client’s public key and unique address:
[Peer]
PublicKey = LAPTOP_PUBLIC_KEY
AllowedIPs = 10.66.0.2/32
Append it to wg0.conf, protect the client file with sudo chmod 600 /etc/wireguard/laptop.conf, and restart wg-quick@wg0. Bring up the connection with sudo wg-quick up laptop. A recent handshake in sudo wg show confirms that the keys, UDP path, and tunnel settings agree.
Many Australian homes now rely on smart televisions and streaming boxes that cannot run WireGuard directly. The privacy trade-offs of those always-connected devices are explained in a smart television privacy overview, while the networking answer is usually to install WireGuard on a compatible OpenWrt router or protect a separate streaming device. A router-wide tunnel can disrupt local casting, banking, and gaming services, so route only the devices that need it. A VPN does not change the licensing terms for Australian sport or streaming services.
Verify operation and maintain the setup
Test from the client while watching the server logs. The tunnel address should answer pings. For a full tunnel, the public address should also match the VPS; a split tunnel deliberately leaves that traffic on the local network.
ping -c 3 10.66.0.1
ping -c 3 1.1.1.1
dig +short myip.opendns.com @resolver1.opendns.com
sudo wg show should display a recent handshake and transferred byte counters. If the tunnel address replies but a full-tunnel public lookup fails, investigate NAT, forwarding, or DNS. View service messages with sudo journalctl -u wg-quick@wg0 -n 50 --no-pager.
Routine maintenance is mostly predictable: apply security updates, confirm the service starts after a reboot, and remove unused client credentials from wg0.conf. Keep client private keys on their devices, back up the server configuration securely, and rotate a key when a device is lost. Changing a peer’s public key requires editing the relevant block on both sides and restarting the service.
Document the tunnel subnet, DNS choice, endpoint, and backup location so the service can be rebuilt without guesswork. The concrete next step is to connect one test client and verify the first handshake in sudo wg show.