WSL 2: "sudo apt-get update" gives "Temporary failure resolving ..." error

PMM 11 Reputation points
2022-03-29T01:45:14.467+00:00

Installed WSL 2 (Debian, but previously tried Ubuntu with same issues). Installation went smoothly, but when I tried the following:

wsl2-prompt> sudo apt-get update

I get the following output to the terminal:

Err:1 http://security.debian.org/debian-security bullseye-security InRelease
Temporary failure resolving 'security.debian.org'
Err:2 http://deb.debian.org/debian bullseye InRelease
Temporary failure resolving 'deb.debian.org'
Err:3 http://ftp.debian.org/debian bullseye-backports InRelease
Temporary failure resolving 'ftp.debian.org'
Err:4 http://deb.debian.org/debian bullseye-updates InRelease
Temporary failure resolving 'deb.debian.org'
Reading package lists... Done
W: Failed to fetch http://deb.debian.org/debian/dists/bullseye/InRelease Temporary failure resolving 'deb.debian.org'
W: Failed to fetch http://deb.debian.org/debian/dists/bullseye-updates/InRelease Temporary failure resolving 'deb.debian.org'
W: Failed to fetch http://security.debian.org/debian-security/dists/bullseye-security/InRelease Temporary failure resolving 'security.debian.org'
W: Failed to fetch http://ftp.debian.org/debian/dists/bullseye-backports/InRelease Temporary failure resolving 'ftp.debian.org'
W: Some index files failed to download. They have been ignored, or old ones used instead.

I am aware that there are networking issues with WSL 2 and have spent 4 days trying to sort out my issues. Unfortunately, there are many "try this, try that" suggestions out there with no clear answer (and certainly no clear reason for why there is this problem to begin with). Many of the suggestions actually contradict each other, which is not helpful (e.g., "change /etc/wsl.conf to have 'generateResolvConf=false' versus just putting 'generateResolvConf' per the learn.microsoft.com troubleshooting guides)

I do have Cisco AnyConnect but the problem I am experiencing (see above) occurs independent of whether VPN is working or not, so the underlying issue does not seem to be related to the "Cisco AnyConnect" problem for which I have also seen suggestions posted.

For the record, I have successfully installed WSL1 and have full "apt-get upgrade" capability. The problem is inherent with WSL2.

I have tried a hundred different combinations of things, like changing the contents of /etc/resolv.conf, /etc/wsl.conf, ~/.wslconfig, etc as suggested by several resources including including https://learn.microsoft.com/en-us/windows/wsl/troubleshooting, https://gist.github.com/coltenkrauter/608cfe02319ce60facd76373249b8ca6, https://janovesk.com/wsl/2022/01/21/wsl2-and-vpn-routing.html

Summary: what do I need to do, step-by-step, to get "sudo apt-get update" to work without a "Temporary failure resolving ..." error in my WSL2/Debian installation?

Windows 10 Network
Windows 10 Network
Windows 10: A Microsoft operating system that runs on personal computers and tablets.Network: A group of devices that communicate either wirelessly or via a physical connection.
2,261 questions
{count} votes

3 answers

Sort by: Most helpful
  1. MuhammadIbrahimSiddiqui-8377 40 Reputation points
    2023-04-28T10:07:31.6866667+00:00

    IF anyone is still stuck, this might be helpful. Found that the issue is due to the WSL is not getting DNS routed somehow.

    How to fix

    Run sudo nano /etc/resolv. conf to change the target DNS server

    In nano overwrite the listed IP to your preferred DNS e.g. local DNS server, internet gateway/router or public DNS. I used these
    nameserver 8.8.4.4

    nameserver 8.8.8.8

    Save and exit

    Run sudo apt-get update again. It will work like charm

    8 people found this answer helpful.

  2. Limitless Technology 39,301 Reputation points
    2022-04-05T03:22:19.757+00:00

    Hi @PMM

    This error can happen when fetching the latest repositories during " apt-get update " was interrupted, and a subsequent " apt-get update " is not able to resume the interrupted fetch. In this case, remove the content in /var/lib/apt/lists before retrying " apt-get update ".

    For many users, this problem seems to be related to VPN. Check if starting WSL-Ubuntu and then connecting the VPN is resolving your problem if you are using any VPN on your PC.

    Try this Powershell command wsl --shutdown And then restart wsl and see if this sorts the issue. Even though it is a simple restart this has helped a lot of users.

    Hope this resolves your Query!!

    -----------

    --If the reply is helpful, please Upvote and Accept it as an answer–

    4 people found this answer helpful.

  3. mustafa ismail eyi 1 Reputation point
    2022-06-08T09:52:42.883+00:00

    Hello, @Limitless Technology

    I haven't used the wsl for a while like 7 month on my old laptop. Then, suddenly I faced the problem above. As you suggested write the "wsl --shutdown" on powershell and restart the wsl then it worked properly.

    Thank you for your help!
    Have a nice day.

    0 comments No comments