WSL DNS Lookups
I have been playing around with WSL (Windows Subsystem for Linux) on and off for a while. It is kind of cool to have a full on Linux/Unix shell on Windows. WSL does have a few quirks after all it is still Windows!
One of the quirks is that WSL does not use or set the search domain of the Windows host. This means that domain name lookups require a fully qualified domain name, which is a pain. I.e.:
ping host_on_my_network.internal_domain_name.local
vs.
ping host_on_my_network
Here is the fix I was able to cobble together.
- sudo cp /etc/resolv.conf /etc/resolv.conf.new
- Edit /etc/resolv.conf.new Add search <internal_domain_name.local>. Save
- sudo unlink /etc/resolv.conf
- sudo cp /etc/resolv.conf.new /etc/resolv.conf
- sudo touch /etc/wsl.conf
- Add following to /etc/wsl.conf
[network]
generateResolvConf = false
Other wsl.conf options can be found here:
FINAL STEP:
exit WSL and run wsl --shutdown
Important: Do NOT restart wsl right away.
According to the documentation it takes at about 8 seconds for wsl to reload or some such. It took me several attempts to get this to work properly.
My recommendation:
Take this opportunity to get a cup of coffee, smell the flowers, or call someone you love, by the time you come back wsl should work the way that you want it to.