Categories
WSL

WSL 2 VPN Routing Fix

In my last article on WSL 2 VPN issues, I detailed the most common networking problems that occur when using WSL 2 and a VPN at the same time. I have since created a Windows service that will automatically correct any conflicting routes that exist between WSL and your VPN.

If you would simply like to use the service, you can download wslroutesvc.exe and run .\wslroutesvc.exe install from PowerShell as an administrator.

If you are interested in how this service functions, read on.

WSL Routing Conflict Service

The WSL Routing Conflict Service (wslroutesvc.exe) is a Windows service created in Go. It periodically checks for routes that match the vEthernet (WSL) interface’s IP and deletes them if they have a different assigned interface. Any changes are logged to the Windows Event Log.

Workflow

  • Gather interface ID and IP for vEthernet (WSL) interface.
    • If the interface does not exist, do nothing.
  • Find and parse all network routes.
  • If a given route fulfills all of the following requirements, delete it:
    • Contains the vEthernet (WSL) interface IP in its network.
    • Has a network mask greater than or equal to 16 (255.255.x.x).
    • Is not assigned to the vEthernet (WSL) interface.

Further Reading

If you are interested in creating your own Windows service with Go, the golang.org/x/sys GitHub repository contains a helpful example at https://github.com/golang/sys/tree/master/windows/svc/example.

Official documentation on the golang.org/x/sys/windows/svc package is available at https://pkg.go.dev/golang.org/x/sys/windows/svc.

Leave a Reply

Your email address will not be published. Required fields are marked *