Tutorials · Security Operations
How to Set Up a WireGuard VPN Server for Remote Access
WireGuard is a fast, modern VPN with a small, auditable code base. Build a WireGuard server on Linux, add users with their own keys and route them only to the networks they need.
Before you start
- A Linux server or edge server (Ubuntu 22.04/24.04 or Debian 12) reachable from the Internet on one UDP port
- Root access
- A free private subnet for VPN clients, for example 10.99.0.0/24
Step by step
Install WireGuard
WireGuard is part of the Linux kernel since 5.6; install the tools.
sudo apt update && sudo apt install -y wireguardCreate the server keys
Each side has its own key pair. Keep private keys readable by root only.
umask 077 wg genkey | sudo tee /etc/wireguard/server.key | wg pubkey | sudo tee /etc/wireguard/server.pub
Write the server configuration
Pick a UDP port and the VPN subnet. Each [Peer] block is one user device.
# /etc/wireguard/wg0.conf [Interface] Address = 10.99.0.1/24 ListenPort = 51820 PrivateKey = <contents of server.key> [Peer] # alice-laptop PublicKey = <alice public key> AllowedIPs = 10.99.0.10/32
Enable routing and firewall rules
Allow forwarding, then only let VPN users reach the networks they need (here the server VLAN 10.1.20.0/24).
echo 'net.ipv4.ip_forward=1' | sudo tee /etc/sysctl.d/99-wg.conf && sudo sysctl --system sudo iptables -A FORWARD -i wg0 -d 10.1.20.0/24 -j ACCEPT sudo iptables -A FORWARD -i wg0 -j DROP
Start the tunnel
Bring up the interface and enable it at boot. Open UDP 51820 on the Internet firewall to this server only.
sudo systemctl enable --now wg-quick@wg0 sudo wg show
Create a client configuration
Generate keys on the client (or for the user), add its public key as a peer on the server, and give the user this file or a QR code for the mobile app.
[Interface] PrivateKey = <alice private key> Address = 10.99.0.10/32 DNS = 10.1.10.1 [Peer] PublicKey = <server public key> Endpoint = vpn.example.com:51820 AllowedIPs = 10.1.0.0/16 # split tunnel: only company networks PersistentKeepalive = 25
Remove users who leave
Delete the [Peer] block and apply the change without dropping other users.
sudo wg set wg0 peer <alice public key> remove # and delete the block from wg0.conf
Commands are generic, industry-standard examples. Exact syntax and menu names vary by model and firmware; check your device's manual on the Documentation page.
Pro tips
- One key per device: a lost phone is removed without affecting the user's laptop.
- WireGuard has no user/password login. Combine it with device management, or use a VPN gateway that adds MFA if your policy requires it.
- Log handshakes with 'wg show wg0 latest-handshakes' to see who is connected.
FAQ
Frequently asked questions
WireGuard or IPsec?
WireGuard is simpler and fast for remote access and small site links. IPsec is the standard for connecting to firewalls and cloud VPN gateways from other vendors.
Full or split tunnel?
Split tunnel (only company subnets in AllowedIPs) saves bandwidth. Use full tunnel (0.0.0.0/0) when policy requires all traffic to pass your security controls.
Keep learning
Related guides
Remote-access VPN for staff
Read more →Site-to-site IPsec VPN
Read more →Fix MTU problems on VPN links
Read more →How to Scan Your Network for Vulnerabilities With Nmap and OpenVAS
Find open ports, outdated services and known vulnerabilities before attackers do. Discover hosts with Nmap, then run authenticated vulnerability scans with Greenbone OpenVAS and fix what matters first.
Read more →How to Build a Free SIEM With Wazuh for Network and Server Logs
A SIEM collects logs from servers, firewalls and switches in one place and alerts on attacks. Install Wazuh, add agents and syslog sources, and tune the first alerts.
Read more →How to Detect Network Attacks With Suricata IDS on a Mirror Port
An intrusion detection system watches a copy of your traffic and alerts on scans, exploits and malware traffic. Install Suricata on a sensor connected to a switch mirror port.
Read more →Stuck on a step?
Ask Navijin technical support or an authorised partner for help with your configuration.