Fixing some issues with WSL2 and Wireguard

byGinkSun, 25 May 2025

1. The first annoying thing when working with WSL2 is Docker Desktop.

I think Docker Desktop is the most common tool for containers on Windows. But it turns out consumes a lot of memory and CPU on the device. Not to mention about the unstable connection between the host (Windows) and applications running inside WSL2.

Solution: Just get rid of Docker Desktop and install docker-ce right in WSL2. It's so smooth and working without any issues.

2. Reading files from NTFS directories are too slow.

This is the common problem with WSL2, when we put files in NTFS folders (from Windows) and try to open them inside WSL.

Solution: Bring your codebase into WSL, install VSCode with WSL extension and things will be fine.

3. Can't connect to internet from WSL2 when it stands behind WireGuard VPN.

If you're using OpenVPN, it seems to be working smoothly. But WireGuard somehow has a problem.

Solution: Open your WireGuard configuration and edit the client configuration [Peer]

[Peer]
AllowedIPs = ::/128, 0.0.0.0/1, 128.0.0.0/1

Can connect to internet from WSL2 but some connections failed, especially with https

Let's check the default network of WSL

ip link show eth0

In case the MTU is higher than 1420. You have to update it to 1420 manually

sudo ip link set eth0 mtu 1420

Can connect to internet from WSL2 with WireGuard. But docker containers still can't?

This is because of default MTU of WireGuard is 1420. And Docker networks always use default MTU 1500.

Solution: Change the default configuration of Docker to set MTU 1420

  • Open this file in WSL: /etc/docker/daemon.json (or create a new one if it doesn't exist) and update it with this setting:
{
  "mtu": 1420
}
  • For networks created by docker-compose.yml. Can change the MTU by configuration like below:
services:
  demo:
    image: alpine:3.20
    container_name: demo_alpine
    command: sleep infinity
    networks:
    - "bridge_network"

networks:
  bridge_network:
    driver: bridge
    driver_opts:
      com.docker.network.driver.mtu: 1420

4. If none of above solutions can fix your network issue?

The final solution is modifying your WSL configuration and change it to mirrored. This is not recommended because it can cause some conflicts with app running in Windows. But it can always fix your WSL2 network issues.

  • Let's open this file C:\Users\<User>\.wslconfig in Windows (or create a new one) and update this setting
[experimental]
networkingMode=mirrored
dnsTunneling=true

Notes: You will need to shutdown your WSL and turn on again to make this change take effect.

5. Some networks issue with Windows itself, not WSL

After upgrading to Windows 11, I encounter a strange problem with Wi-fi network. When the device is waking up from sleep. The wireless network can't connect again. And even the Wi-fi card driver is disabled in Device Manager.

Turns out the driver was also in sleep mode with Windows but could not be woken up. But checking driver configuration in Device Manager, there's no option to prevent it from sleeping anymore. This happens with Windows 11 only.

Solution: modify the registry to turn on this option:

  • Open Regedit.
HKLM\System\CurrentControlSet\Control\Power
  • Add new DWORD PlatformAoAcOverride (0)

  • Open Device manager -> Wi-fi Device -> Power Management -> Disable Allow to turn off

  • Restart and then update PlatformAoAcOverride to (1) again

6. Last but not least, memory and CPU consumption by WSL

WSL seems to be not very efficient in resource management

  • Let's open .wslconfig again and update with some limits
[wsl2]
memory=12GB
swap=12GB
processors=8

I've allocated 12GB of RAM and 8 CPU on my device to WSL but you can change with any number you want. Based on your device and the needs.

And if it looks not enough for you. Let's try some other options to make Windows revoke allocated memory faster.

[experimental]
autoMemoryReclaim=dropcache
sparseVhd=true

That's it. Quite a trouble to work with WSL, isn't it? But after finishing all these fixes. I got a smooth experience with it. Just like working on a Linux device.

I hope you get a good experience with it as well. Good luck!


© 2016-2025  GinkCode.com