Skip to content

Instantly share code, notes, and snippets.

@leiless
Last active May 30, 2024 07:38
Show Gist options
  • Save leiless/ed840780452bab10e3b6fc7b54cff46a to your computer and use it in GitHub Desktop.
Save leiless/ed840780452bab10e3b6fc7b54cff46a to your computer and use it in GitHub Desktop.
How to restore default `/etc/resolv.conf` on WSL 2

https://learn.microsoft.com/en-us/windows/wsl/wsl-config#network-settings

/etc/wsl.conf

[boot]
systemd=true

[network]
generateResolvConf=true

generateResolvConf=true is the key to restore default /etc/resolv.conf.

And then:

wsl.exe --shutdown
# or
sudo reboot

Verify

$ cat /etc/resolv.conf
# This file was automatically generated by WSL. To stop automatic generation of this file, add the following entry to /etc/wsl.conf:
# [network]
# generateResolvConf = false
nameserver 172.29.64.1

$ ip route
default via 172.29.64.1 dev eth0 proto kernel
172.29.64.0/20 dev eth0 proto kernel scope link src 172.29.70.49

$ route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         172.29.64.1     0.0.0.0         UG    0      0        0 eth0
172.29.64.0     0.0.0.0         255.255.240.0   U     0      0        0 eth0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment