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;
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?
Provided an elevated shell session is used, it is possible to modify the Windows
hostsfile within WSL (Windows Subsystem for Linux). It would be useful if hostile supported working with Windows hosts within WSL.An example of adding hosts;
With standard host drive mount configuration,
wslpath -u -a C:\\Windows\\System32\\drivers\\etc\\hostsreturns/mnt/c/Windows/System32/drivers/etc/hosts. The resolved path should be treated as case sensitive.Thoughts?