Due to the way WSL is configured by default some DNS resolutions may fail e.g. using a VPN or using Node dns.resolveMX()
This repo provides scripts to manually update and revert the DNS server to resolve these issues based on Microsoft Docs: WSL has no network connectivity once connected to a VPN for the default Ubuntu 22.04 on WSL2.
Disclaimer: Use at your own risk! Make sure your read and understand any scripts before running them!
There are two scripts:
updatedns <IPv4 address e.g. 192.168.0.1>- To get the DNS server open a PowerShell and type
ipconfig.exe /alland look for the lineDNS Servers . . . . . . . . . . . : x.x.x.xon the adapter in use
- To get the DNS server open a PowerShell and type
revertdns
One way to use these would be to
$ mkdir ~/.local/bin && cd ~/.local/bin
$ git clone <url repo> .
$ chmod +x updatedns revertdnsThen add the scripts' path to your shell PATHS