A WireGuard handshake and a home public IP can look reassuring while the laptop still uses a resolver learned on the visited network. With a working full route, its DNS query may pass through home and then return to that resolver, exposing the questions despite using the tunnel. Check routing, resolver selection and off-tunnel failure behavior separately so each part matches your privacy goal.
The Setup That Almost Works
A minimal config looks like this on the server:
[Interface]
Address = 10.0.0.1/24
ListenPort = 51820
PrivateKey = <server-private-key>
[Peer]
PublicKey = <client-public-key>
AllowedIPs = 10.0.0.2/32
With wg-quick on the client, AllowedIPs = 0.0.0.0/0 installs an IPv4 default route through WireGuard. If the client has IPv6 connectivity, use AllowedIPs = 0.0.0.0/0, ::/0 and configure IPv6 forwarding/routing on the server too; otherwise IPv6 can bypass an IPv4-only tunnel. After wg-quick up, a ping to 10.0.0.1 and an external IP check confirm routing, but you still need to verify DNS behavior and failure handling. If wg-quick tears down or a network manager changes routes, the normal physical-interface route can become usable again. An endpoint timeout while the interface stays up may instead black-hole traffic; test both failure modes.
Enable forwarding on the server. Without it, the server won’t route packets from the WireGuard interface to the outside world. For an IPv4-only tunnel, set this permanently in /etc/sysctl.conf:
net.ipv4.ip_forward=1
For an IPv6 full tunnel, also enable IPv6 forwarding and provide a valid routed or translated IPv6 path:
net.ipv6.conf.all.forwarding=1
Apply with sysctl -p, then verify both address families you intend to carry.
Routing Traffic Properly with iptables
To make the server a gateway, add NAT masquerading so return traffic finds its way back:
iptables -t nat -A POSTROUTING -s 10.0.0.0/24 -o eth0 -j MASQUERADE
This rewrites the source address of the example tunnel subnet when it leaves eth0, so replies return through the home host. A separately configured route for 10.0.0.0/24 could avoid NAT, but the ordinary home-router example uses masquerading. Confirm eth0 is actually the upstream interface before applying the rule.
If the server's FORWARD policy does not already allow this path, permit the example tunnel subnet out and only return traffic back in:
iptables -A FORWARD -i wg0 -o eth0 -s 10.0.0.0/24 -j ACCEPT
iptables -A FORWARD -i eth0 -o wg0 -d 10.0.0.0/24 -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT
Keep the return rule limited to the traffic you intend to permit. A broad -o wg0 -j ACCEPT would allow unsolicited traffic from other interfaces toward tunnel clients, while an unscoped POSTROUTING -j MASQUERADE could rewrite other paths. Match both the forwarding and masquerading scope to the example subnet and actual upstream interface.
Use PostUp and PostDown hooks to apply and remove these rules automatically. In the server’s [Interface] section:
PostUp = iptables -A FORWARD -i %i -o eth0 -s 10.0.0.0/24 -j ACCEPT; iptables -A FORWARD -i eth0 -o %i -d 10.0.0.0/24 -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT; iptables -t nat -A POSTROUTING -s 10.0.0.0/24 -o eth0 -j MASQUERADE
PostDown = iptables -D FORWARD -i %i -o eth0 -s 10.0.0.0/24 -j ACCEPT; iptables -D FORWARD -i eth0 -o %i -d 10.0.0.0/24 -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT; iptables -t nat -D POSTROUTING -s 10.0.0.0/24 -o eth0 -j MASQUERADE
%i expands to the interface name (wg0). The rules appear when the interface comes up and disappear when it goes down, keeping firewall state predictable.
The DNS Leak You’ll Miss
Even with a default route through the tunnel, a client can keep using a resolver learned from its local network. As Ubuntu’s default-gateway guide notes, an ordinary full route may carry those queries through the VPN and back to that resolver; the visited network’s resolver then still learns your questions. A specific local route, IPv6 path or application DNS can change the exposure. Check the actual route and active resolver instead of calling every unwanted resolver an off-tunnel packet leak.
Fix it on the client first. In the client’s [Interface] section, add:
DNS = 1.1.1.1
Here 1.1.1.1 is an example public resolver reached through the configured IPv4 default route. It can see the questions. Use 10.0.0.1 instead only after a resolver is installed on that server address, allowed from the tunnel, and tested. The upstream wg-quick manual[1] defines DNS in terms of resolvconf: it adds the resolver when the interface comes up and removes it when the interface goes down. Distribution integrations differ. If NetworkManager or systemd-resolved owns DNS on your system, configure the WireGuard connection through that manager or use matching PostUp/PostDown commands such as resolvectl dns and resolvectl domain; verify the active resolver state instead of assuming the line was honored.
If you own the server firewall policy and operate a resolver at 10.0.0.1, you can optionally redirect conventional port-53 queries from tunnel clients to it. Test direct resolution at 10.0.0.1 first. Redirecting to a service that is absent would break DNS, so establish the working resolver before adding the enforcement rules.
Redirecting Plain DNS with iptables
The following DNAT rules can redirect conventional TCP/UDP DNS on port 53 from tunnel clients, ideally through PostUp:
iptables -t nat -A PREROUTING -i wg0 -p udp --dport 53 -j DNAT --to-destination 10.0.0.1:53
iptables -t nat -A PREROUTING -i wg0 -p tcp --dport 53 -j DNAT --to-destination 10.0.0.1:53
These DNAT examples require a resolver listening on 10.0.0.1; add matching PostDown deletion rules if you put them in PostUp, or manage them with your existing persistent firewall instead. If you redirect to an external resolver, the server still sends that query over its own uplink. These rules cover ordinary DNS on port 53 only. They do not intercept DNS-over-TLS, DNS-over-HTTPS or DNS-over-QUIC, and they do not force applications to use the operating system’s resolver. Call this port-53 enforcement rather than a guarantee that every name lookup uses your resolver.
If you run a local resolver like Unbound, ensure it listens on the WireGuard interface. Unbound defaults to listening on localhost when no interfaces are specified. Integrate settings like these into the active Unbound configuration and check its syntax; do not replace the whole file with this fragment:
server:
interface: 10.0.0.1
access-control: 10.0.0.0/24 allow
Verifying No Leaks
Test with dig from the client, targeting a domain you haven’t visited recently:
dig example.com
On the server, run tcpdump -ni any port 53 while issuing a known test query. You should see the client-side packet arrive on wg0 and the resolver handle it. A local resolver may send upstream queries on eth0, so outbound DNS on the server is not by itself a client-side off-tunnel leak. Also inspect the client’s routes and resolver state, and test both IPv4 and IPv6. Port-53 packet capture cannot detect application-level encrypted DNS.
Building a Real Kill Switch
A kill switch should reject ordinary packets that would leave outside the tunnel while still allowing WireGuard’s own marked UDP transport to reach the peer. Check any exceptions carefully: a broad ESTABLISHED,RELATED allowance can let an already-established flow continue over a physical interface after the route changes. The road-warrior setup explains the server path; this section focuses on the client guard.
The wg-quick manual’s kill-switch example[1] uses WireGuard’s firewall mark and removes the exact rule during teardown:
[Interface]
...
PostUp = iptables -I OUTPUT ! -o %i -m mark ! --mark $(wg show %i fwmark) -m addrtype ! --dst-type LOCAL -j REJECT
PreDown = iptables -D OUTPUT ! -o %i -m mark ! --mark $(wg show %i fwmark) -m addrtype ! --dst-type LOCAL -j REJECT
That example is for IPv4. An IPv6 full tunnel also needs an IPv6 rejection rule and ::/0 in AllowedIPs, along with the working server route described above. The following is the core rejection rule, not a complete IPv6 firewall. Before using it, allow the narrowly scoped ICMPv6 control traffic required on the physical uplink, including neighbor discovery and router discovery when used. An unconditional rejection rule at the top of OUTPUT can block those packets and break the uplink. RFC 4890[2] describes the essential local ICMPv6 messages; preserve those exceptions ahead of the rejection rule in your existing firewall. The -I OUTPUT hook below inserts at the head of the chain, so adapt its insertion position or use a dedicated chain to ensure the required exceptions run first; do not paste it unchanged onto a dual-stack host.
PostUp = ip6tables -I OUTPUT ! -o %i -m mark ! --mark $(wg show %i fwmark) -m addrtype ! --dst-type LOCAL -j REJECT
PreDown = ip6tables -D OUTPUT ! -o %i -m mark ! --mark $(wg show %i fwmark) -m addrtype ! --dst-type LOCAL -j REJECT
Here LOCAL means an address assigned to the client itself, not every address on the visited LAN. Ordinary packets to another LAN host are rejected when they take the physical interface and lack the WireGuard mark. Add only the narrowly scoped local exceptions you intend, and verify the required IPv6 control traffic separately.
The Lockout Risk
Test the kill switch with local or out-of-band console access available. Bring the tunnel down deliberately and confirm PreDown removes exactly the rule it inserted; a syntax error or missing teardown hook can otherwise lock out a remote machine. For recovery, remove the test rule or use the host’s normal firewall rollback. A blanket iptables -F would also remove unrelated policy.
These client rules reject ordinary off-tunnel IP packets while the interface is up, within their stated IPv4/IPv6 and local-destination scope. DNS still deserves its own verification because resolver choice and encrypted application DNS can behave differently. Test what happens during a tunnel outage, reconnection and teardown; a PostUp rule is not a permanent host-wide firewall policy.
Verify the full tunnel in the conditions where you will use it: inspect routes and resolver state, cover every available address family, and test outages and teardown from a console you can still reach. Repeat those checks after network-manager or operating-system updates. That gives you evidence about the traffic path and failure behavior, beyond the handshake alone.