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
/etc/wsl.conf
file. You'll need sudo access for this:
sudo vi /etc/wsl.conf
[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
:wq
This will save the file and exit the vi editor
/etc/resolv.conf
file with a new DNS entry. First edit the file, simiar to step 1 above:
sudo vi /etc/resolv.conf
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
insert
mode by pressing Esc
: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