Last active
April 28, 2021 12:03
-
-
Save antriver/1321a8e32c50ed2452db1762c4d7ebd3 to your computer and use it in GitHub Desktop.
Add a "wsl.local" entry to both the WSL and Windows hosts file, pointing to the IP address of WSL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# You must run this script from an "elevated terminal", that means right click on Windows Terminal and "Run as Administrator". | |
# Then run it with `sudo wsl-ip.sh` from within WSL. | |
# Remove existing wsl.local lines | |
sed -i '/wsl.local/d' /etc/hosts | |
sed -i '/wsl.local/d' /mnt/c/Windows/system32/drivers/etc/hosts | |
# Add to WSL hosts file | |
echo "`ifconfig | sed -En 's/127.0.0.1//;s/.*inet (addr:)?(([0-9]*\.){3}[0-9]*).*/\2/p'` wsl.local" >> /etc/hosts | |
# Add to Windows hosts file | |
echo "`ifconfig | sed -En 's/127.0.0.1//;s/.*inet (addr:)?(([0-9]*\.){3}[0-9]*).*/\2/p'` wsl.local" >> /mnt/c/Windows/system32/drivers/etc/hosts |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment