WireGuard VPN
WireGuard is a modern, fast, and secure VPN protocol. With the wg-easy Docker image, setup is particularly easy.
Installation
Add the following template to your docker-compose.yml and then run ei23 dc.
Router Configuration Required
After installation, you need to forward port 51820 UDP on your router to the server.
Template
wireguard:
image: ghcr.io/wg-easy/wg-easy
container_name: wireguard
restart: unless-stopped
cap_add:
- NET_ADMIN
- SYS_MODULE
environment:
- LANG=en
- WG_HOST=your-domain-or-ip.org
- PASSWORD=yourpassword
- PORT=51821
- WG_PORT=51820
- WG_DEFAULT_ADDRESS=10.8.8.x
- WG_DEFAULT_DNS=
- WG_ALLOWED_IPS=0.0.0.0/1, 128.0.0.0/1, ::/1 # Full VPN
# - WG_ALLOWED_IPS=10.8.8.0/24, 172.18.0.0/24 # only local VPN
volumes:
- ./volumes/wireguard:/etc/wireguard
ports:
- "51820:51820/udp"
- "51821:51821/tcp"
sysctls:
- net.ipv4.conf.all.src_valid_mark=1
Configuration
Environment Variables
| Variable | Description | Example |
|---|---|---|
WG_HOST | Your domain or public IP | mydomain.com or 85.123.45.67 |
PASSWORD | Password for the web interface | SecurePassword123! |
WG_PORT | WireGuard port (UDP) | 51820 |
PORT | Web interface port (TCP) | 51821 |
WG_DEFAULT_ADDRESS | IP range for clients | 10.8.8.x |
WG_ALLOWED_IPS | Routes through VPN | See below |
WG_ALLOWED_IPS Options
# Option 1: Full VPN (all traffic through the tunnel)
WG_ALLOWED_IPS=0.0.0.0/1, 128.0.0.0/1, ::/1
# Option 2: Only home network through VPN (rest of internet directly)
WG_ALLOWED_IPS=10.8.8.0/24, 192.168.178.0/24
Recommended
For Smart Home use: Use Option 2 (home network only) for better everyday speed.
Configure Router
Fritz!Box
- Go to Internet → Permit Access
- Click New Port Forwarding
- Settings:
- Protocol: UDP
- Port: 51820
- To IP: IP of your server
- Description: WireGuard
Other Routers
Forward the following ports: - 51820 UDP → Your server (WireGuard) - 51821 TCP → Your server (Web interface, optional)
First Start
- After startup, you can access the web interface at
http://[IP]:51821 - Log in with the configured
PASSWORD - Create a new client:
- Click + New Client
- Enter a name (e.g., "My Phone")
- Download the configuration or scan the QR code
Set Up Client
Smartphone (Android/iOS)
- Install the WireGuard app:
- Android
- iOS
- In the wg-easy interface, click the QR code icon
- Scan the QR code with the app
- Activate the VPN
Desktop (Windows/macOS/Linux)
- Install the WireGuard client:
- Windows
- macOS
- Linux:
sudo apt install wireguard - Download the configuration file (.conf)
- Import the file in the client
- Activate the VPN
VPN Types Explained
Full VPN
Advantages: Maximum privacy, ad blocking (with Pi-hole) Disadvantages: Slower, server bandwidth limited
Split Tunnel (Home Network Only)
Advantages: Faster in everyday use Disadvantages: Only home network services protected
Notes
- Data is stored in
./volumes/wireguard/ - The web interface is accessible on port 51821
- WG_HOST must be your public IP or domain
- For dynamic IPs, use Dynamic DNS
- WireGuard is significantly faster than OpenVPN
Security
- The
PASSWORDonly protects the web interface - Each client has its own key
- Deactivate unused clients in the interface
- Regular updates of the Docker image
Troubleshooting
VPN Won't Connect
- Check port forwarding on the router (UDP 51820)
- Check
WG_HOST- must be public IP/domain - Check firewall on the server
- Test with
ping 10.8.8.1to see if the tunnel works
Slow Connection
- Use split tunnel (
WG_ALLOWED_IPShome network only) - Check upload speed of your internet connection
- Change
WG_MTU=1280if there are fragmentation issues