• Stars
    star
    1,647
  • Rank 28,377 (Top 0.6 %)
  • Language
    Go
  • Created over 5 years ago
  • Updated 3 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Automatically update your Windows hosts file with the WSL2 VM IP address

go-wsl2-host

Latest Build
Latest Build

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

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: <username-you-use-to-login-to-windows>
Windows Password: <password-for-this-user>

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

More Repositories

1

wsl2-hacks

Useful snippets / tools for using WSL2 as a development environment
Shell
1,292
star
2

hwinfo-streamdeck

Monitor sensor readings with this HWiNFO64 Stream Deck Plugin
CSS
233
star
3

react-native-webview-js-context

Utilize the JavaScript VM running inside an iOS UIWebView to exploit libraries targeting the DOM (e.g. Google Charts)
Java
85
star
4

PowerDimmer

Distraction dimmer for Windows ala HazeOver/LeDimmer
C#
73
star
5

stock-ticker-stream-deck-plugin

A stock ticker plugin for Stream Deck
CSS
25
star
6

PianoKeys

Control Pianobar using Mac media keys
Objective-C
23
star
7

SSUnreadBubble

A CoreGraphics implementation of the iPhone unread mail message blue bubble
Objective-C
22
star
8

TTPickerTextFieldDemo

Demonstrates the ability use a TTPickerTextField from the Three20 library, outside the TTMesageController
Objective-C
20
star
9

tsnet-serve

Tailscale Serve in a tsnet app
Go
17
star
10

tailscale-docker

Automated Tailscale Docker Build
12
star
11

nxbot

Telegram security camera bot using Nx Witness
Go
10
star
12

dotfiles

My dotfiles, borrowed from ryanb and rtomayko
Shell
7
star
13

vmproxy

A tsnet Tailscale proxy for VNC and libvirt virsh control over a VM
JavaScript
6
star
14

apple-xcode3-solarized

Solarized - Xcode 3 Color Presets
6
star
15

phonad

A WIP of implementing a Xmonad inspired config for kasper/phoenix
JavaScript
6
star
16

iPhoneWebCamera

A proof of concept demonstrating use of the iPhone's photo library and camera from an HTML application
C
5
star
17

go-streamdeck-sdk

Lightweight client library written in Go for the Stream Deck SDK
Go
5
star
18

vim-config

My ~/.vim
Vim Script
5
star
19

junior

Junior was inspired by Ruby's Sinatra in an attempt "for quicky creating web-applications in [ColdFusion] with minimal effort":
4
star
20

SSXcodeProjectTemplates

My customized Xcode iPhone project templates
Objective-C
3
star
21

wtf-fivem-ev-tesla

Repository moved: https://github.com/wtf-fivem-mods/wtf_ev
Lua
2
star
22

react-native-component-explorer

JavaScript
2
star
23

reason-devcontainer

Reason
2
star
24

shake

Make things happen; a flexible alternative to using make for running tasks.
C
2
star
25

nixos-config

Nix
2
star
26

go-winpeg

Golang Windows Process Exit Group convenience library
Go
2
star
27

docker-mods

2
star
28

react-native-navigation-buttons

JavaScript
2
star
29

clicursor

Go
1
star
30

logupdate

Go
1
star
31

zwave

My attempt to build a code driven zwave automation system in Go
JavaScript
1
star
32

tripod

Tripod is a module that samples running scripts, logging tracebacks to a temp file.
Python
1
star
33

controller-aircraft-reporter

Scrape Controller.com and email new/updated aircraft alerts
Python
1
star