Skip to content

WSL DNS Quick Fix Guide

TL;DR - Fix DNS Now

If DNS is broken (ping google.com fails but ping 8.8.8.8 works):

# Run the automated fix
mise run fix:wsl-dns

# Then restart WSL (from PowerShell on Windows)
wsl --shutdown

# Verify
ping google.com

Detection

Check if you have DNS issues:

# Run health check
mise run doctor

# Or manually test
ping google.com        # Fails = DNS broken
ping 8.8.8.8          # Works = Network OK, DNS broken

Two Ways to Fix

mise run fix:wsl-dns

This script: - ✅ Detects current DNS status - ✅ Diagnoses the configuration problem - ✅ Deploys the correct /etc/wsl.conf - ✅ Provides next steps

Then restart WSL:

# From PowerShell
wsl --shutdown

Option 2: Manual

# 1. Copy the correct config
sudo cp ~/repos/dotfiles/dot_config/wsl/wsl.conf /etc/wsl.conf

# 2. Verify it was applied
grep generateResolvConf /etc/wsl.conf
# Should show: generateResolvConf=true

# 3. Restart WSL (from PowerShell)
wsl --shutdown

# 4. Test DNS
ping google.com

Why This Happens

Root Cause: Configuration mismatch between WSL's DNS management and systemd-resolved.

When you have: - ✅ systemd=true (systemd enabled) - ❌ generateResolvConf=false (WSL DNS disabled)

Then: 1. systemd-resolved runs but has no upstream DNS servers 2. Network changes (VPN, sleep/wake) cause systemd-resolved to lose DNS config 3. DNS resolution fails until WSL restarts

The Fix: Set generateResolvConf=true to let WSL auto-manage DNS from Windows.


Prevention

This repository's dotfiles now have:

  1. Correct Default: generateResolvConf=true in dot_config/wsl/wsl.conf
  2. Health Check: mise run doctor detects DNS issues
  3. Quick Fix: mise run fix:wsl-dns automates recovery

Verification Checklist

After applying the fix:

  • /etc/wsl.conf has generateResolvConf=true
  • Restarted WSL with wsl --shutdown
  • ping google.com works
  • cat /etc/resolv.conf shows Windows DNS servers (not 127.0.0.53)
  • mise run doctor passes DNS checks

"DNS works after reboot but fails later"

→ This is the exact symptom. Run mise run fix:wsl-dns

"VPN breaks DNS in WSL"

→ Fixed by letting WSL manage DNS (generateResolvConf=true)

"systemd-resolved shows 'Current Scopes: none'"

→ Means systemd-resolved has no DNS servers. Run the fix.


Advanced: Understanding the Fix

Before (Broken)

# /etc/wsl.conf
[boot]
systemd=true

[network]
generateResolvConf=false  # ❌ WSL won't manage DNS

Result: - systemd-resolved runs but has no upstream DNS - /etc/resolv.conf127.0.0.53 (systemd stub) - systemd-resolved has nowhere to forward queries - DNS fails

After (Fixed)

# /etc/wsl.conf
[boot]
systemd=true

[network]
generateResolvConf=true   # ✅ WSL manages DNS from Windows

Result: - WSL auto-generates /etc/resolv.conf from Windows DNS - Syncs automatically with network changes - DNS always works


Troubleshooting

If the fix doesn't work:

  1. Check Windows DNS:

    # From PowerShell
    ipconfig /all
    # Look for "DNS Servers"
    

  2. Verify WSL is using mirrored networking:

    # Check %USERPROFILE%\.wslconfig
    cat /mnt/c/Users/$USER/.wslconfig
    # Should have: networkingMode=mirrored
    

  3. Check for VPN interference:

  4. Some VPNs block WSL DNS tunneling
  5. Try disconnecting VPN temporarily
  6. Or add dnsTunneling=true to .wslconfig

  7. Full diagnosis:

    mise run doctor
    resolvectl status
    cat /etc/resolv.conf
    cat /etc/wsl.conf
    


See Also