{"id":13459956,"url":"https://github.com/shayne/go-wsl2-host","last_synced_at":"2025-05-15T14:05:40.672Z","repository":{"id":35940144,"uuid":"194497293","full_name":"shayne/go-wsl2-host","owner":"shayne","description":"Automatically update your Windows hosts file with the WSL2 VM IP address","archived":false,"fork":false,"pushed_at":"2024-08-10T07:39:40.000Z","size":61,"stargazers_count":1660,"open_issues_count":47,"forks_count":140,"subscribers_count":23,"default_branch":"master","last_synced_at":"2025-05-15T14:05:31.737Z","etag":null,"topics":["wsl","wsl2"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/shayne.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-06-30T09:17:26.000Z","updated_at":"2025-04-19T10:01:28.000Z","dependencies_parsed_at":"2024-05-28T03:16:01.603Z","dependency_job_id":"1336d524-f95e-4b1b-9163-e74f321a16cb","html_url":"https://github.com/shayne/go-wsl2-host","commit_stats":null,"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shayne%2Fgo-wsl2-host","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shayne%2Fgo-wsl2-host/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shayne%2Fgo-wsl2-host/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shayne%2Fgo-wsl2-host/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/shayne","download_url":"https://codeload.github.com/shayne/go-wsl2-host/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254355334,"owners_count":22057354,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["wsl","wsl2"],"created_at":"2024-07-31T10:00:32.972Z","updated_at":"2025-05-15T14:05:35.662Z","avatar_url":"https://github.com/shayne.png","language":"Go","funding_links":[],"categories":["Go","语言资源库"],"sub_categories":["go"],"readme":"# go-wsl2-host\n\n[Latest Build \u003cbr/\u003e ![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)\n\n\u003e 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.\n\n\u003e Unable to enter your username? Having trouble starting the service? See [issue #10](https://github.com/shayne/go-wsl2-host/issues/10#issuecomment-562631992)\n\nA workaround for accessing the WSL2 VM from the Windows host.\n\nThis 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.\n\nThe 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.\n\nI 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.\n\nTo install and run, download a binary from the releases tab. Place it somewhere like your `Documents/` folder.\n\nOpen an **elevated/administrator** command prompt:\n\n```\n\u003e .\\wsl2host.exe install\nWindows Username: \u003cusername-you-use-to-login-to-windows\u003e\nWindows Password: \u003cpassword-for-this-user\u003e\n```\n\nThe program will install a service and start it up. \n\nThe 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 \u003e Log on as a service`, and add your username.\n\nLaunch `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.\n\nThe Windows hosts file is located at: `C:\\Windows\\System32\\drivers\\etc\\hosts`\n\n**To remove / uninstall the service:**\n\n_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`_\n\nOpen an **elevated/administrator** command prompt:\n\n```\n\u003e .\\wsl2host.exe remove\n```\n\n**Specifying aliases**\n\nAs 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.\n\nTo do this, create the file `~/.wsl2hosts` in your default WSL2 distro. Host names are space separated:\n```\nsome.client.local my-app.local wsl.local\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshayne%2Fgo-wsl2-host","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fshayne%2Fgo-wsl2-host","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshayne%2Fgo-wsl2-host/lists"}