WSL2: Temporary failure in name resolution

New setup of WSL2 on Windows 10. Attempting to run sudo apt update for the first time gave me this error. Here's 'a' solution

  1. Firstly, edit the /etc/wsl.conf file. You'll need sudo access for this:
    sudo vi /etc/wsl.conf
  2. Yes it may be empty when you first edit it. Add the following contents to the file:
    [network]
    generateResolvConf = false

    If you are using vi for the first time, you need to enter insert mode first by pressing the i key. Once the content has been entered, the Esc key will take you out of insert mode and put you into command mode

  3. Now save the file by using the following command:
    :wq

    This will save the file and exit the vi editor

  4. Now to update the /etc/resolv.conf file with a new DNS entry. First edit the file, simiar to step 1 above:
    sudo vi /etc/resolv.conf
  5. There should already be a nameserver entry, all you need to do is update the IP address listed. If working from a local (home) internet connection, you probably want to use the IP of your router. If you're working elsewhere, you will probably want to use a public provider like Cloudflare (1.1.1.1) or Google (8.8.8.8). I'll use Cloudflare for now as an example. Don't forget to enter insert mode by pressing the i key first:
    nameserver 1.1.1.1
  6. Exit insert mode by pressing Esc
  7. Now save the file by using the following command:
    :wq

    This will save the file and exit the vi editor.

Now you've been returned to the prompt, you should hopefully find connectivity to the outside world is working


Previous Post Next Post

Add a comment

Comments

cBZawrqoiLdhnT
Written on Sat, 06 Jul 2024 13:23:10 by LgfmBsvz
UcMgSJzCVKRmbTH
Written on Tue, 28 May 2024 18:20:18 by lWawJKNh
hHwaqeJrdQMR
Written on Tue, 14 May 2024 11:42:23 by CufrOMULjBbXKVD