As far as I've been able to work out, the official process for changing which DNS server is used by WSL2 on Windows 10 is as detailed below. (WSL2 is the new release of the Windows Subsystem for Linux, which runs an actual Linux kernel in a lightweight VM on Windows 10.)
However, this process doesn't work for me - I end up with a system that simply times out and can't resolve any addresses whatsoever.
What am I doing wrong?
Here's the process as I've pieced it together so far:
1. Turn off generation of /etc/resolv.conf
Using your Linux prompt, (I'm using Ubuntu), modify (or create) /etc/wsl.conf with the following content
[network]
generateResolvConf = false
(Apparently there's a bug in the current release where any trailing whitespace on these lines will trip things up.)
2. Restart the WSL2 Virtual Machine
Exit all of your Linux prompts and run the following Powershell command
wsl --shutdown
3. Create a custom /etc/resolv.conf
Open a new Linux prompt and cd to /etc
If resolv.conf is soft linked to another file, remove the link with
rm resolv.conf
Create a new resolv.conf with the following content
nameserver 1.1.1.1
4. Restart the WSL2 Virtual Machine
Same as step #2
5. Start a new Linux prompt.
Profit!
Update March 18, 2020
My /etc/hosts file contains this:
# This file was automatically generated by WSL. To stop automatic generation of this file, add the following entry to /etc/wsl.conf:
# [network]
# generateHosts = false
127.0.0.1 localhost
127.0.1.1 [redacted] bearps-desktop
10.168.244.140 host.docker.internal
10.168.244.140 gateway.docker.internal
127.0.0.1 kubernetes.docker.internal
# The following lines are desirable for IPv6 capable hosts
::1 ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
The file /etc/switch.conf does not exist.
The tool resolvectl is not on my path; it doesn't exist at /usr/bin/resolvectl.
Likewise systemd-resolve is not on my path; it doesn't exist at /usr/bin/systemd-resolve.