Seafile Server
From research to recommendation in one place.
VPN Guides · en

WireGuard on Ubuntu

By Renata Pereira · October 29, 2026 · 6 min · Updated October 29, 2026
WireGuard on Ubuntu
WireGuard on Ubuntu

A practical guide to installing, configuring, and managing WireGuard on Ubuntu for secure VPN connections.

the article body in Markdown:

WireGuard on Ubuntu: a practical guide to install, configure, and manage a fast, secure VPN

WireGuard has become a popular choice for VPN needs on Ubuntu thanks to its simplicity, performance, and strong cryptography. This guide walks you through the steps to get WireGuard up and running, from installation to maintenance, with a practical example you can adapt to your environment.

VPN

Getting started: what you need before you begin

Before you install WireGuard on Ubuntu, gather a few basics:

  • An Ubuntu server or desktop (18.04 LTS or newer is ideal; 22.04 LTS is common).
  • Sudo access on the system.
  • At least two devices for a practical tunnel (one peer acting as the server, another as the client).
  • A basic understanding of network addressing, including private and public IPs.
  • Optional: a domain or dynamic DNS if you plan to reach the VPN server from the internet with a stable name.

On Ubuntu, WireGuard is included in the kernel and user space tools, so you’ll typically install the package wireguard-tools and ensure the kernel module is loaded.

Installing WireGuard on Ubuntu

Follow these steps to install WireGuard and prepare your environment:

  • Update system packages:
  • sudo apt update && sudo apt upgrade -y
  • Install WireGuard components:
  • sudo apt install -y wireguard-tools linux-headers-$(uname -r) wireguard-dkms
  • Verify the module is loaded:
  • sudo modprobe wireguard
  • dmesg | grep -i wireguard should show something if loaded
  • Check the version and availability:
  • wg, version
  • wg show all 2>/dev/null || echo "No interfaces yet"

Note: Depending on your Ubuntu release, some steps may be simplified by using the in-kernel implementation if you’re on a newer kernel that has WireGuard built-in. The wireguard-dkms package helps if you’re on an older kernel.

Creating a basic server and client configuration

WireGuard works with peers defined by public/private keys and a peer list. A simple tunnel requires: WireGuard on Unraid: a practical guide to setting up secure VPN access

  • A private key for each peer
  • The public key of each peer
  • An interface IP address (for example 10.0.0.1/24 for the server and 10.0.0.2/24 for the client)
  • A listen port on the server (commonly 51820)

Key generation (on each peer):

  • umask 077
  • wg genkey | tee privatekey | wg pubkey > publickey

Typical server config (e.g., /etc/wireguard/wg0.conf):

  • [Interface]
  • PrivateKey = your_server_private_key
  • Address = 10.0.0.1/24
  • ListenPort = 51820
  • [Peer]
  • PublicKey = client_public_key
  • AllowedIPs = 10.0.0.2/32

Typical client config (e.g., /etc/wireguard/wg0.conf):

  • [Interface]
  • PrivateKey = your_client_private_key
  • Address = 10.0.0.2/24
  • [Peer]
  • PublicKey = server_public_key
  • Endpoint = your_server_ip_or_domain:51820
  • AllowedIPs = 0.0.0.0/0,::/0
  • PersistentKeepalive = 25

Notes:

  • AllowedIPs on the client side defines which traffic goes through the VPN. 0.0.0.0/0,::/0 routes all traffic through the tunnel.
  • On the server, you can restrict AllowedIPs to specific subnets to limit the VPN exposure.

Enabling IP forwarding and configuring firewall rules

To allow VPN traffic to pass through the server, enable IP forwarding: WireGuard on Synology NAS: a practical guide to setting up and using VPN on Synology

  • sudo sysctl -w net.ipv4.ip_forward=1
  • sudo sysctl -w net.ipv6.conf.all.forwarding=1
  • To make it persistent, add net.ipv4.ip_forward=1 and net.ipv6.conf.all.forwarding=1 to /etc/sysctl.conf and reboot or sysctl -p.

If you’re using a firewall (for example UFW), open the WireGuard port and enable NAT for traffic from the VPN to the internet:

  • sudo ufw allow 51820/udp
  • sudo ufw enable
  • Use iptables or nftables to masquerade VPN traffic. A common iptables snippet:
  • sudo iptables -t nat -A POSTROUTING -s 10.0.0.0/24 -o eth0 -j MASQUERADE
  • sudo iptables -A FORWARD -i wg0 -j ACCEPT
  • sudo iptables -A FORWARD -o wg0 -j ACCEPT
  • Save iptables rules if you want them to persist across reboots.

Managing WireGuard as a system service

With systemd, you can manage the WireGuard interface as a service for automatic startup and easy control.

Troubleshooting tips:

  • If the interface won’t come up, check the file permissions and syntax in wg0.conf.
  • Use sudo wg show to inspect peer handshakes and data transfer. A stale handshake means recent traffic hasn’t occurred. Wait or generate a new key handshake by restarting the service.
  • Verify that the server’s firewall allows inbound traffic on the WireGuard port (51820/udp by default) and that NAT is configured if you want outbound traffic to reach the internet.

A practical comparison: WireGuard vs other VPN options on Ubuntu

Here is a quick comparison to help you decide how WireGuard stacks up against common alternatives: How to set up a VPN server on an Asus router in 2026

VPN feature WireGuard on Ubuntu OpenVPN on Ubuntu IPsec (strongSwan) on Ubuntu
Setup complexity Low to moderate Moderate to high Moderate
Performance Very high (kernel-level) Moderate to high Moderate
CPU usage Low Higher Moderate
Configuration style Simple, key-based Complex config files Complex, multiple components
Security model Modern crypto primitives Classic ciphers and TLS Mature, flexible but heavier
Cross-platform support Excellent Excellent Excellent
Ideal use case Quick, secure site-to-site or client VPN; light admin overhead Enterprise, client-to-site with granular options Mixed deployments, legacy VPNs, site-to-site with IPSec tunnels

Note: WireGuard shines when you want a lean, fast, and easy-to-manage VPN with strong cryptography and minimal overhead. OpenVPN and IPsec remain solid options in environments with specific compatibility or policy requirements.

Security considerations and best practices

  • Use strong keys and rotate them periodically. Keep private keys on devices secure with proper filesystem permissions (readable only by root or the user running the service).
  • Keep the server and clients updated. Enable automatic security updates where appropriate.
  • Limit AllowedIPs on peers to the minimum needed. For a client that only needs access to a specific service, restrict to that service’s IP or subnet instead of 0.0.0.0/0.
  • Consider a dedicated VPN VM or container for isolation in more complex environments.
  • Monitor handshake activity with sudo wg show and log any unusual activity. Enable log verbosity for troubleshooting if needed.

Common pitfalls and troubleshooting checklist

  • Connection not establishing:
  • Check that the server is reachable on the UDP port (nc -zv server_ip 51820).
  • Verify that the server and client have matching public keys in the peer sections and that the private keys are kept secret.
  • Confirm that the gateway and firewall rules allow WireGuard traffic.
  • Handshake never completes:
  • Ensure time synchronization on both peers. A skew can disrupt cryptographic handshakes.
  • Check the Endpoint field on the client to ensure it points to the correct public IP/domain and port.
  • Traffic not routing through VPN:
  • Confirm IP forwarding is enabled.
  • Check that the server has NAT rules for traffic from the VPN subnet.
  • Inspect AllowedIPs on the client; 0.0.0.0/0 routes all traffic, but you can limit to specific subnets for split tunneling.

A short, practical setup recap

  • Install: sudo apt update && sudo apt install -y wireguard-tools linux-headers-$(uname -r) wireguard-dkms
  • Generate keys on server and client, place in wg0.conf with proper addresses (e.g., 10.0.0.1/24 for server, 10.0.0.2/24 for client).
  • Enable IP forwarding and configure firewall/NAT.
  • Start and enable the service: sudo wg-quick up wg0. Sudo systemctl enable wg-quick@wg0
  • Verify with: sudo wg show and test connectivity by pinging the client from the server and vice versa.

Final recommendation

If your goal is a fast, secure, and straightforward VPN on Ubuntu, WireGuard is the recommended starting point. It’s kernel-level on modern Ubuntu releases, which translates to excellent performance and a small attack surface. Start small with a single server-client tunnel, ensure IP forwarding and basic firewall rules are in place, then expand to multiple peers or a site-to-site mesh as needed. Keep the configuration simple, rotate keys periodically, and stay on top of updates to keep your VPN resilient and secure.

© 2026 Seafile Server. All rights reserved.