-
-
Notifications
You must be signed in to change notification settings - Fork 50
Open
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;
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
doneWith 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?
Metadata
Metadata
Assignees
Labels
No labels