Frequent loss of network using opensuse running on WSL2 via VSCode

Paul Gardiner 0 Reputation points
2025-07-29T10:04:30.5233333+00:00

I commonly use opensuse running under WSL2 via VSCode for software development. While it works at all, it works very well. Fairly frequently (perhaps every other day), I lose the network: DNS still works, but there is no route for IP traffic (pings fail). A reboot doesn't fix it. The only fix I've found so far is to remove the Hyper-V feature, reboot, readd the Hyper-V feature, and reboot again. That breaks my WIndows network, so I also have to reconfigure the Windows network to use DHCP. rather than some strange manual setting it has dreamed up. Then I'm back up and running for a few days.

Please does anyone have any idea what might be the root problem, and how I might fix it, or perhaps a quicker fix (like perhaps restarting the service that runs Hyper-V's network... I don't know what to look for).

Developer technologies | C++
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Varsha Dundigalla(INFOSYS LIMITED) 795 Reputation points Microsoft External Staff
    2025-07-30T08:25:52.2366667+00:00

    Thank you for reaching out.

    If you're losing network in WSL2 (openSUSE) — where DNS still works but pings and IP traffic fail — and you're currently fixing it by reinstalling Hyper-V, there's a much faster way.

    Quick Fix (No reboot needed)

    Quick Fix for WSL2 Network Loss (PowerShell)

    Open PowerShell as Administrator and run:

    Restart-Service -Force hns
    Restart-Service -Force LxssManager
    wsl --shutdown
    Restart-NetAdapter -Name "vEthernet (WSL)"
    

    Fix DNS Issues in WSL (Terminal)

    Open your WSL terminal and run:

    sudo sed -i 's/nameserver .*/nameserver 8.8.8.8/' /etc/resolv.conf
    

    Prevent WSL from overwriting this on restart:

    sudo nano /etc/wsl.conf
    

    Add the following lines:

    [network]
    generateResolvConf = false
    

    Then restart WSL:

    wsl --shutdown
    

    Check Hyper-V Virtual Switch

    If the problem keeps coming back:

    • Open Hyper-V Manager → Virtual Switch Manager
    • Make sure the switch used for WSL is set to Internal Network
    • Ensure vEthernet (WSL) in Windows network settings is using DHCP

    Avoid using "External Network" — it often causes conflicts.

    Other Things to Check

    • If you use a VPN, test your WSL network on Wi-Fi instead of Ethernet
    • Make sure firewall software isn’t blocking vmcompute.exe or wslhost.exe
    • Full Windows Network Reset (PowerShell or CMD)

    Open PowerShell or Command Prompt as Administrator and run:

      netsh winsock reset
      netsh int ip reset
      ipconfig /flushdns
      shutdown /r /t 0
    

    Keep Everything Updated

    • Update WSL: wsl --update
    • Update Windows
    • Update VSCode and the Remote - WSL extension

    This should fix your issue and prevent you from having to reinstall Hyper-V every few days.
    Let me know if you need any help with this

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.