How to route all traffic through a WireGuard tunnel
Configure AllowedIPs and NAT masquerading to route all internet traffic through a WireGuard VPN tunnel.
How to route all traffic through a WireGuard tunnel
Configure AllowedIPs and NAT masquerading to route all internet traffic through a WireGuard VPN tunnel.
Prerequisites
- A working WireGuard tunnel between client and server.
- NAT/masquerading configured on the WireGuard server.
Step-by-Step: Route All Traffic Through WireGuard
On the client, set
AllowedIPs = 0.0.0.0/0, ::/0in the[Peer]section ofwg0.conf. This tells WireGuard to route all IPv4 and IPv6 traffic through the tunnel:[Peer] PublicKey = <SERVER_PUBLIC_KEY> Endpoint = server.example.com:51820 AllowedIPs = 0.0.0.0/0, ::/0On the server, verify masquerading is active. The
PostUprules in the server'swg0.confmust include NAT masquerading:PostUp = iptables -A FORWARD -i wg0 -j ACCEPT; iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADESet the DNS server in the client's
[Interface]section to prevent DNS leaks:[Interface] DNS = 1.1.1.1, 1.0.0.1Restart the tunnel:
sudo wg-quick down wg0 && sudo wg-quick up wg0
How to Verify All Traffic Routes Through the Tunnel
Check the public IP from the client — it should show the server's IP:
curl ifconfig.me