Support for setting Windows hosts within WSL
- Dominant language
- JavaScript
- Stars
- 794
- Forks
- 49
- PR merge metrics
- No merged PRs in 30d
Description
Provided an elevated shell session is used, it is possible to modify the Windows `hosts` file within WSL (Windows Subsystem for Linux). It would be useful if hostile supported working with Windows hosts within WSL.
An example of adding hosts;
```bash
declare -a LOCAL_DOMAINS=("some-site.test" "api.some-site.test")
# add Domains to hosts
for domain in ${LOCAL_DOMAINS[@]}
do
if grep -q microsoft /proc/version; then
declare -a windowsHosts=$(wslpath -u -a C:\\Windows\\System32\\drivers\\etc\\hosts);
if ! grep --quiet ${domain} $windowsHosts; then
echo "Adding ${domain} to Windows hosts file..."
echo "127.0.0.1 ${domain}" | tee -a $windowsHosts || { echo >&2 "Failed to add entry to hosts file - ${domain}, try running WSL terminal instance as admin" ; exit 1; }
fi
fi
done
```
With standard host drive mount configuration, `wslpath -u -a C:\\Windows\\System32\\drivers\\etc\\hosts` returns `/mnt/c/Windows/System32/drivers/etc/hosts`. The resolved path should be treated as case sensitive.
Thoughts?
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.