Fixed addresses between Windows, WSL and a VM with WireGuard
3 December 2026
I run coding agents in WSL, and some of them need to drive a browser. The browser runs on Windows, where I can see it, and the agents talk to it over the Chrome DevTools Protocol. A small relay on Windows exposes each browser’s debugging port so that WSL can connect to it.
The DevTools Protocol has no authentication. Whoever can reach the port controls the browser, along with any session that is logged in there. So before anything else, I wanted that port reachable from exactly the machines that need it and from nothing else on the network.
The problem
WSL2 gets a new eth0 address on every boot, and so does the Windows
host as seen from inside WSL. From WSL you can look the host up each
time:
ip -4 route show default | awk 'NR==1 {print $3}'
That works, but every script and config that points at Windows has to do it, and there is no equally simple answer in the other direction. What I wanted was:
- Simple: an address I can type, the same after every reboot.
- Not exposed: nothing on the LAN reaches the relay.
- Extensible: I can add another machine later, such as a Hyper-V VM on the same host.
- Separate: this link stays apart from the other networks I run, such as the mesh I use to manage my servers.
WireGuard covers all four. It is already how I connect my servers, it needs a key to talk to at all, and adding a peer is a few lines of config.
The design
Windows is the hub on 10.0.0.1. WSL is 10.0.0.2, and later a
Hyper-V VM joined as 10.0.0.3. On Windows the tunnel runs as a
service in WireGuard for Windows, listening on UDP 54321. In WSL it is
wg-quick@devlink0, enabled at boot.
Each peer’s AllowedIPs on the Windows side is its own /32, and
Windows does not forward between peers. WSL and the VM can both talk to
Windows, but not to each other. I checked: the VM routes 10.0.0.0/24
into the tunnel and gets no reply from WSL.
WSL always initiates
The hard part is that WSL’s address changes, so Windows cannot have an
Endpoint for it. Instead, Windows has no endpoint for the WSL peer at
all and learns it from the first handshake. WSL is the side that dials,
and since the Windows address it dials also changes per boot, it looks
it up when the interface comes up:
[Interface]
Address = 10.0.0.2/24
# eth0 MTU is 1420, minus 60 bytes of WireGuard overhead.
MTU = 1360
PostUp = wg set %i peer <windows-public-key> endpoint $(ip -4 route show default | awk 'NR==1 {print $3}'):54321
[Peer]
# Windows host
AllowedIPs = 10.0.0.1/32
PersistentKeepalive = 25
The private key is in the same file and is left out here. The
[Peer] section has no Endpoint; PostUp sets it once the interface
exists.
The cost is that Windows cannot reach WSL until WSL has sent its first handshake. The 25 second keepalive keeps that gap to a few seconds after boot, but anything on Windows that connects to WSL at startup should expect to retry once.
The VM has a fixed LAN address, so its config is the ordinary kind,
with an Endpoint pointing at the host:
[Interface]
Address = 10.0.0.3/24
MTU = 1360
[Peer]
Endpoint = <host-lan-address>:54321
AllowedIPs = 10.0.0.0/24
PersistentKeepalive = 25
MTU
WSL’s eth0 has an MTU of 1420, not 1500. WireGuard over IPv4 adds 60
bytes, so the tunnel is set to 1360. With the default the tunnel comes
up and small requests work, and then large responses stall, which is a
confusing way to find out.
What “not exposed” actually means
I assumed the tunnel alone kept the relay private. It does not, quite.
The VM connects from its LAN address, so Windows accepts WireGuard packets on UDP 54321 from the LAN. That part is fine: WireGuard does not answer anything that is not signed with a known peer’s key, so a scanner gets no response at all. What matters is what a peer can reach once it is in.
When I wrote this up I went and checked, and the firewall rule I had for the tunnel allowed any program on any port from both peers. The VM could reach SMB and RPC on the host as well as the relay. Nothing was wrong yet, but if the VM were ever compromised, that rule was its way onto the host.
The rule is now two, one per service, each scoped to the port and the peers that need it:
New-NetFirewallRule -DisplayName 'CDP relay over devlink0' `
-Direction Inbound -Action Allow -Protocol TCP -InterfaceAlias devlink0 `
-LocalAddress 10.0.0.1 -LocalPort 9222-9300 `
-RemoteAddress 10.0.0.2,10.0.0.3
The second rule is the same shape for a proxy port that only the VM
uses. After the change I probed from both peers: the relay answers, SMB
and RPC do not. The relay also refuses to start if it is configured to
bind anything other than 10.0.0.1, so a typo cannot turn it into a
LAN service.
The firewall rules themselves came out of preparing for Cyber Essentials, the UK government’s baseline security certification.
Separate meshes
Because each tunnel is its own interface with its own keys, keeping networks apart takes no extra effort. On this machine there are three:
- this one, for the browser relay, between Windows, WSL and the VM;
- a mesh from Windows to the Hyper-V guests I use for other work;
- a mesh from WSL to my servers, which Windows cannot reach.
None of them routes into the others.
Things to know
- After restarting the WSL side, reconnecting takes 5 to 10 seconds, because WireGuard backs off between handshake attempts.
- Changing the Windows side needs an elevated shell, and the config is kept in WireGuard’s protected store rather than a file you can read.
Mirrored networking
After I had all this working, I found out that WSL has a mirrored
networking mode, which shares the host’s interfaces with WSL so that
localhost works in both directions. For WSL alone it would probably
have been enough, and simpler. It does not help the VM, though, and it
does not give me a separate network that I can scope on its own. So
this setup turned out to be the better fit, but I did not choose it
for that reason.
I wrote this post with Claude Code, Anthropic’s AI coding tool, using the Claude Opus 5.5 model.