wsl2-dns v1.0.0
WSL2 DNS synchronizer.
Install:
- Run:
npm i -g wsl2-dns - From your Windows installation go to
C:\Windows\System32\drivers\etcand take ownership of this file and/or make it writable from non-elevated Notepad instance. You can do that manually, but I recommend to use WinAero Tweaker to addTake ownershipentry into file context menu.
How it works:
This app will update IPs of your existing domains defined in Windows' hosts file to match wsl2 distro IP address
(which changes when wsl2 shuts down).
It will not add new entries.
Note that Windows does not support wildcard subdomains, so you still have to list your domains manually there even if
you run wsl2-dns with wildcard subdomains specified.
Usage:
wsl2-dns domain1 [domain2 domain3 ...domainN]
^ wheredomainis either a full domain name to update or "wildcard" name starting with.dot to update all subdomains of that domain (excluding root domain itself!)
Example:
wsl2-dns bigproject.local .localhost
^ to updatebigproject.local,small.localhost,other.localhost, but notlocalhost
Warning: It is not recommended to replace
localhostroot level domain. Some Windows apps may rely on that pointing to 127.0.0.1.
Recommended usage
- put
wsl2-dnscommand in your~/.profilefile, this way each time you start a new terminal window you will have your dns domains updated - choose single or multiple top-level domain (
.localhostor any custom, I use.dzek) to avoid updating the.profilefile each time you add new subdomain (remember you need to update Windows'hostsfile)
FAQ / Errors:
Error:
hostsfile is not writable.
See Install part of this file. Running as root will not help - it's the Windows host that prevents editing the file, not Linux permissions.
Error: Specify domains to update
See Usage.
Error:
ip addrcommand failed to start
Your distro is missing ip application.
- Debian/Ubuntu: install it with
sudo apt-get install iproute2 - Centos: install it with
yum install iproute - Other distros: You have to Google that yourself.
Could not find IP address
ip addr returns unexpected results. This apps looks for eth0 network IP address. Please try running ip addr
manually and report an issue.
License
MIT