Goals Achieved
This runbook documents the complete setup procedure for a secure, split-tunnel WireGuard homelab. By the end of this guide, the following will be in place:
- The main server runs a WireGuard server on the
wg0 interface, acting as the VPN hub for the network.
- Pi 1 and Pi 2 each run a WireGuard client, connecting back to the server as authenticated tunnel peers.
- A split tunnel is configured so that only VPN subnet traffic traverses WireGuard. All other internet traffic continues to use each device’s local gateway at full speed.
- AdGuard Home runs locally on a Pi and retains full DNS control. WireGuard does not override system DNS, preventing common resolution failures.
- Optional: Docker hosts on each Pi are monitored by Uptime Kuma over the WireGuard tunnel, using a read-only socket proxy.
- Optional: IPv6 is permanently disabled at the kernel and firewall level to eliminate dual-stack complexity.
- UFW enforces a default-deny firewall policy, with only explicitly required ports open to the public internet.
1. WireGuard on the Main Server (Server Side)
1.1 Install WireGuard
sudo apt update
sudo apt install -y wireguard
1.2 Generate the Server Keypair
WireGuard uses public-key cryptography. Each peer has a private key (kept secret) and a derived public key (shared with other peers). The following command generates both in a single pipeline and saves them to the standard WireGuard directory:
wg genkey | sudo tee /etc/wireguard/server.key | wg pubkey | sudo tee /etc/wireguard/server.pub >/dev/null
sudo chmod 600 /etc/wireguard/server.key
The chmod 600 command restricts the private key file to root-only read access. WireGuard will refuse to start if the private key file has overly permissive permissions.
1.3 Create the Server Configuration
sudo nano /etc/wireguard/wg0.conf
Paste the following and replace <SERVER_PRIVATE_KEY> with the contents of /etc/wireguard/server.key:
[Interface]
Address = 10.8.0.1/24
ListenPort = 51820
PrivateKey =
To retrieve the private key value for pasting:
sudo cat /etc/wireguard/server.key
The server is assigned 10.8.0.1 — the first address in the VPN subnet — and will act as the gateway for all tunnel peers. Peer entries ([Peer] blocks for each Raspberry Pi) will be added in Step 3 after the Pi keys are generated.
1.4 Enable and Start the WireGuard Interface
sudo systemctl enable wg-quick@wg0
sudo systemctl start wg-quick@wg0
sudo wg
The systemctl enable command ensures the WireGuard interface starts automatically on every boot. The sudo wg command displays the current tunnel status. At this point, the server will show a listening interface but no connected peers — that is expected until the Pi clients are configured and their public keys are added.
2. WireGuard on Raspberry Pi 1 and Pi 2 (Client Side)
Perform the following steps on each Raspberry Pi, substituting the correct IP address for each device. Pi 1 uses 10.8.0.2 and Pi 2 uses 10.8.0.3.
2.1 Install WireGuard
sudo apt update
sudo apt install -y wireguard
2.2 Generate the Client Keypair
wg genkey | tee ~/client.key | wg pubkey > ~/client.pub
chmod 600 ~/client.key
The public key (~/client.pub) must be copied to the server and added to the server’s wg0.conf in Step 3. The private key (~/client.key) stays on this Pi and is referenced in the client configuration below.
2.3 Create the Client Configuration
Pi 1 Configuration (10.8.0.2)
sudo nano /etc/wireguard/wg0.conf
[Interface]
Address = 10.8.0.2/24
PrivateKey =
# No DNS directive — AdGuard Home manages DNS locally on this device
[Peer]
PublicKey =
Endpoint = :51820
AllowedIPs = 10.8.0.0/24
PersistentKeepalive = 25
Pi 2 Configuration (10.8.0.3)
Use the same configuration structure, with the following values changed:
Address = 10.8.0.3/24
PrivateKey =
All other fields — PublicKey, Endpoint, AllowedIPs, and PersistentKeepalive — remain identical.
Critical: the split-tunnel rule.
AllowedIPs = 10.8.0.0/24 ✅ Correct — routes only VPN subnet traffic through the tunnel
AllowedIPs = 0.0.0.0/0 ❌ Wrong — creates a full-tunnel VPN, routing all internet traffic through the server
The AllowedIPs directive controls both which traffic is sent into the tunnel and which source addresses are accepted from the peer. Using the /24 VPN subnet ensures that only tunnel traffic is affected. Using 0.0.0.0/0 would redirect all internet traffic through the WireGuard server, breaking NAT, degrading performance, and requiring IP forwarding to be enabled on the server — none of which is intended in this design.
PersistentKeepalive = 25 sends a keepalive packet every 25 seconds. This is required because the Raspberry Pis sit behind NAT routers, and NAT state tables will expire idle UDP sessions within one to two minutes of inactivity. Without keepalives, the tunnel silently drops after a period of no traffic.
2.4 Enable and Start on Each Pi
sudo systemctl enable wg-quick@wg0
sudo systemctl start wg-quick@wg0
sudo wg
The interface will start, but the tunnel handshake will not complete until the server’s wg0.conf is updated with this Pi’s public key in the next step.
3. Add Pi Peers to the Main Server
On the main server, open the WireGuard configuration file and append a [Peer] block for each Raspberry Pi:
sudo nano /etc/wireguard/wg0.conf
Add the following blocks at the end of the file, replacing the placeholder values with the actual public keys generated on each Pi in Step 2.2:
[Peer]
PublicKey =
AllowedIPs = 10.8.0.2/32
[Peer]
PublicKey =
AllowedIPs = 10.8.0.3/32
Each peer uses a /32 host mask in AllowedIPs. This tells the server to accept packets from each peer only when they originate from that specific IP address, preventing one peer from injecting traffic that claims to originate from another peer’s tunnel address.
Restart the server interface to apply the changes:
sudo systemctl restart wg-quick@wg0
sudo wg
After restarting, sudo wg should show both peers listed. Once the Pi clients send their first keepalive or data packet, the “latest handshake” timestamp for each peer will update, confirming the tunnel is active.
4. Verify the Split Tunnel Is Correct
4.1 Tunnel Ping Tests
From Pi 1 or Pi 2, verify that the server is reachable over the tunnel:
ping 10.8.0.1
From the server, verify that both Pis are reachable:
ping 10.8.0.2
ping 10.8.0.3
A successful ping in both directions confirms that the tunnel handshake completed and traffic is flowing correctly through the wg0 interface.
4.2 Confirm Internet Traffic Bypasses the Tunnel
On each Pi, inspect the routing table:
ip route
The output must show exactly two relevant entries:
- Default route via LAN gateway — for example,
default via 192.168.1.1 dev eth0. This confirms that all internet-bound traffic exits through the local router, not the VPN tunnel.
10.8.0.0/24 dev wg0 — confirming that VPN subnet traffic is correctly directed into the WireGuard interface.
If the default route points to wg0 instead of the LAN gateway, the tunnel has been accidentally configured as a full tunnel. Bring the interface down immediately with sudo wg-quick down wg0, correct AllowedIPs in the configuration file, then restart the interface. Do not proceed until this is resolved.
5. DNS Configuration (AdGuard Home on Pi)
Because AdGuard Home runs locally on the Raspberry Pi, no DNS = directive should be present in the WireGuard client configuration — and none has been added.
Adding a DNS = line to the WireGuard config would instruct the wg-quick tool to modify /etc/resolv.conf when the tunnel comes up, redirecting all DNS queries through WireGuard. When AdGuard Home is already running locally, this creates a circular dependency: DNS resolution requires the tunnel, and the tunnel endpoint may require DNS resolution to establish. It also means that if the tunnel is temporarily down, all name resolution on the Pi fails — even for entirely local queries.
Because AdGuard Home is co-located on the same device, DNS resolution is already local and requires no tunnel involvement. The correct configuration is to omit the DNS = directive entirely and allow AdGuard Home to manage resolution directly.
6. Optional: Disable IPv6 Permanently (Ubuntu / Raspberry Pi OS)
Disabling IPv6 removes an entire class of dual-stack routing and firewall edge cases. In small homelab environments, the operational complexity of managing rules across two protocol families rarely provides any benefit. The following procedure disables IPv6 at both the kernel level and the firewall level.
6.1 Disable at the Kernel Level (Recommended Method)
sudo nano /etc/sysctl.d/99-disable-ipv6.conf
Paste the following:
net.ipv6.conf.all.disable_ipv6 = 1
net.ipv6.conf.default.disable_ipv6 = 1
net.ipv6.conf.lo.disable_ipv6 = 1
Apply the settings immediately without rebooting:
sudo sysctl --system
Verify that no IPv6 addresses are assigned to any interface:
ip a | grep inet6
If this command produces no output, IPv6 has been successfully disabled at the kernel level. The settings will persist across reboots because the configuration file resides in /etc/sysctl.d/, which is read during every boot sequence.
7. Firewall Configuration (UFW)
7.1 Reset to a Clean State
Before applying the intended ruleset, reset UFW to eliminate any previously configured rules that might conflict or leave unexpected ports open:
sudo ufw disable
sudo ufw reset
sudo ufw default deny incoming
sudo ufw default allow outgoing
The default-deny incoming policy means every inbound packet is dropped unless a specific rule explicitly permits it. This is the foundation of the entire firewall strategy — every open port in this system is a deliberate decision, not an oversight or default.
7.2 Allow Required Ports
SSH (Choose One)
Recommended — WireGuard-only access (most secure):
sudo ufw allow from 10.8.0.0/24 to any port 22 proto tcp comment "SSH via WireGuard only"
This rule permits SSH connections only from addresses within the WireGuard VPN subnet. Because 10.8.0.0/24 is a private address range not routable on the public internet, an attacker cannot reach port 22 without first authenticating through WireGuard. External port scans will show port 22 as filtered — not open, not closed.
Alternative — public SSH with rate limiting (if WireGuard-only is not viable):
sudo ufw limit 22/tcp comment "SSH public with rate limiting"
UFW’s limit action blocks source IPs that attempt more than six connections within 30 seconds. This reduces brute-force exposure but leaves the SSH service reachable from any source IP. Use this only if VPN-gated access is not possible.
HTTP and HTTPS
sudo ufw allow 80/tcp comment "HTTP"
sudo ufw allow 443/tcp comment "HTTPS"
Port 80 is required for Let’s Encrypt ACME HTTP-01 challenge responses during TLS certificate issuance and renewal. Port 443 is the primary public-facing endpoint for any HTTPS services hosted on the server.
WireGuard
sudo ufw allow 51820/udp comment "WireGuard handshake and keepalive"
sudo ufw allow in on wg0 comment "WireGuard tunnel — all internal traffic"
Port 51820 must be open on the public interface so that Raspberry Pi clients can initiate and maintain the WireGuard handshake from behind their home routers. The allow in on wg0 rule permits all traffic arriving on the WireGuard interface. Because WireGuard cryptographically authenticates every packet using public-key cryptography, only peers with a valid keypair can inject traffic into wg0, making blanket allowance on this interface appropriate.
7.3 Enable UFW and Verify
sudo ufw enable
sudo ufw status numbered
sudo ufw status verbose
Review the output of ufw status verbose carefully. Every rule listed should correspond to a service you have intentionally chosen to expose. If any unexpected rules appear, investigate before proceeding.
8. Optional: Docker Monitoring over WireGuard (Uptime Kuma)
8.1 Deploy a Read-Only Docker Socket Proxy on Each Pi
Rather than exposing the raw Docker socket or the full unfiltered Docker API — both of which would grant complete control over every container on the host — a socket proxy is deployed in front of it. The proxy exposes only the read-only API endpoints required by Uptime Kuma (container status, version, ping, and metadata) and blocks everything else.
Create a docker-compose.yml file in a directory of your choice on each Pi:
version: "3.8"
services:
docker-socket-proxy:
image: tecnativa/docker-socket-proxy
container_name: docker-socket-proxy
ports:
- "2375:2375"
environment:
CONTAINERS: 1 # Allow container list and inspect endpoints
INFO: 1 # Allow /info endpoint
PING: 1 # Allow /_ping health check endpoint
VERSION: 1 # Allow /version endpoint
volumes:
- /var/run/docker.sock:/var/run/docker.sock:ro # Mount socket read-only
restart: unless-stopped
Start the proxy:
docker compose up -d
With this configuration, Uptime Kuma can query container health and status, but cannot start, stop, delete, or modify any container. Monitoring capability and control capability are intentionally separated at the API layer.
8.2 Restrict Docker Proxy Access to WireGuard Only
On each Pi, add a UFW rule that permits connections to port 2375 only from addresses within the WireGuard VPN subnet:
sudo ufw allow from 10.8.0.0/24 to any port 2375 comment "Docker socket proxy — WireGuard only"
Port 2375 must never be reachable from the public internet. The combination of the VPN-only UFW rule and the read-only socket proxy provides two independent layers of protection: network-level access control and API-level capability restriction.
8.3 Configure Uptime Kuma
In the Uptime Kuma interface, add a new monitor for each Raspberry Pi with the following settings:
- Monitor Type: Docker Host
- Docker Host URL for Pi 1:
http://10.8.0.2:2375
- Docker Host URL for Pi 2:
http://10.8.0.3:2375
Because Uptime Kuma itself runs on a device within the WireGuard subnet, it can reach these addresses directly over the tunnel. No public internet exposure is involved.
9. Common Pitfalls to Avoid
The following mistakes are frequently made in homelab WireGuard deployments. Each was explicitly considered and avoided in this build:
- ❌ Never expose Docker port 2375 to the public internet. The Docker API grants full control over all containers and images on the host. Exposure to any untrusted network is equivalent to granting root access. Always gate it behind the VPN.
- ❌ Never use
AllowedIPs = 0.0.0.0/0 on clients. This creates a full-tunnel VPN. All internet traffic is routed through the server, introducing NAT requirements, degrading Pi performance, and breaking the split-tunnel design. Always use the specific VPN subnet: 10.8.0.0/24.
- ❌ Never set
DNS = 10.8.0.1 (or any address) unless the WireGuard server is also running a DNS resolver. If AdGuard Home runs on the Pi itself, adding a DNS directive causes WireGuard to override local DNS with a tunnel-dependent resolver, breaking resolution whenever the tunnel is down.
- ❌ Never rely on a Certbot or Caddy HTTPS reverse proxy to secure the Docker API. An HTTPS proxy in front of the Docker socket may restrict which endpoints are reachable over HTTP, but it does not eliminate API access vulnerabilities, does not protect against misconfiguration, and does not provide network-layer isolation. WireGuard plus UFW is the correct security model.
- ✅ Always use WireGuard plus UFW together. WireGuard provides authenticated tunnel access. UFW enforces which tunnel-internal services are accessible and from which addresses. Neither alone is sufficient — both are necessary.
System Health Checklist
Run the following commands on any node after a configuration change, reboot, or any time you want to confirm the system is in the expected state:
sudo wg # Confirm tunnel is active, peers are listed, handshakes are recent
ip route # Confirm default route → LAN gateway, not wg0
sudo ufw status verbose # Confirm expected rules are in place, no unexpected ports are open
ss -tulpen | head -n 30 # Confirm which processes are listening and on which interfaces
For a complete validation, also verify the following behavioral properties:
- Pinging
10.8.0.1 from a Pi succeeds — the VPN tunnel is up.
- Pinging
8.8.8.8 from a Pi succeeds — internet traffic is bypassing the tunnel correctly.
- Pinging
google.com from a Pi succeeds — DNS resolution is functioning independently of the tunnel.
- An external port scan of the server’s public IP shows port 22 as filtered — SSH is not reachable from outside the VPN.
- SSH from a WireGuard peer using the correct key succeeds — VPN-gated access is working as intended.