Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/shayne/go-wsl2-host
Automatically update your Windows hosts file with the WSL2 VM IP address
https://github.com/shayne/go-wsl2-host
wsl wsl2
Last synced: about 18 hours ago
JSON representation
Automatically update your Windows hosts file with the WSL2 VM IP address
- Host: GitHub
- URL: https://github.com/shayne/go-wsl2-host
- Owner: shayne
- Created: 2019-06-30T09:17:26.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2024-08-10T07:39:40.000Z (4 months ago)
- Last Synced: 2024-12-05T13:02:10.859Z (8 days ago)
- Topics: wsl, wsl2
- Language: Go
- Homepage:
- Size: 59.6 KB
- Stars: 1,658
- Watchers: 24
- Forks: 143
- Open Issues: 48
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
- awesomeLibrary - go-wsl2-host - Automatically update your Windows hosts file with the WSL2 VM IP address (语言资源库 / go)
- stars - shayne/go-wsl2-host - Automatically update your Windows hosts file with the WSL2 VM IP address (Go)
- jimsghstars - shayne/go-wsl2-host - Automatically update your Windows hosts file with the WSL2 VM IP address (Go)
README
# go-wsl2-host
[Latest Build
![Latest Build](https://github.com/shayne/go-wsl2-host/actions/workflows/go.yml/badge.svg?tag=latest)](https://github.com/shayne/go-wsl2-host/releases/tag/latest)> As of v0.2.0, I've dropped support for `windows.local`, if this was important let me know and I can add it back in.
> Unable to enter your username? Having trouble starting the service? See [issue #10](https://github.com/shayne/go-wsl2-host/issues/10#issuecomment-562631992)
A workaround for accessing the WSL2 VM from the Windows host.
This program installs as a service and runs under the local user account. It automatically updates your Windows hosts file with the WSL2 VM's IP address.
The program uses the name of your distro, modified to be a hostname. For example "Ubuntu-18.04" becomes `ubuntu1804.wsl`. If you have more than one running distro, it will be added as well. When the distro stops it is removed from the host file.
I wrote this for my own use but thought it might be useful for others. It's not perfect but gets the job done for me.
To install and run, download a binary from the releases tab. Place it somewhere like your `Documents/` folder.
Open an **elevated/administrator** command prompt:
```
> .\wsl2host.exe install
Windows Username:
Windows Password:
```The program will install a service and start it up.
The user account informed must have the right to `logon on as a service`. To do so, run `secpol.msc` command and navigate to `Security Settings - Local policies - User rights assignment > Log on as a service`, and add your username.
Launch `wsl` then from a `cmd` prompt, run `ping ubuntu1804.wsl`. You can check the Windows hosts file to see what was written. The service will automatically update the IP if the WSL2 VM is stopped and started again.
The Windows hosts file is located at: `C:\Windows\System32\drivers\etc\hosts`
**To remove / uninstall the service:**
_NOTE: Upgrading Windows Insider will remove the service, but not cleanly. To reinstall after upgrading, first make sure you've downloaded the latest version of `wsl2host`, then run `remove` before `install`_
Open an **elevated/administrator** command prompt:
```
> .\wsl2host.exe remove
```**Specifying aliases**
As of v0.3 you can now specify aliases that point to your WSL2 VM IP. Having `some.client.local`, may be useful in your development workflow.
To do this, create the file `~/.wsl2hosts` in your default WSL2 distro. Host names are space separated:
```
some.client.local my-app.local wsl.local
```