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.

  1. sudo cp /etc/resolv.conf /etc/resolv.conf.new
  2. Edit /etc/resolv.conf.new Add search <internal_domain_name.local>. Save
  3. sudo unlink /etc/resolv.conf
  4. sudo cp /etc/resolv.conf.new /etc/resolv.conf
  5. sudo touch /etc/wsl.conf
  6. Add following to /etc/wsl.conf
[network]
generateResolvConf = false

Other wsl.conf options can be found here:

Advanced settings configuration in WSL
A guide to the wsl.conf and .wslconfig files used for configuring settings when running multiple Linux distributions on Windows Subsystem for Linux.

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.