Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WSL2 Set static ip? #4210

Open
scrossan-crown opened this issue Jun 21, 2019 · 169 comments
Open

WSL2 Set static ip? #4210

scrossan-crown opened this issue Jun 21, 2019 · 169 comments
Labels

Comments

@scrossan-crown
Copy link

@scrossan-crown scrossan-crown commented Jun 21, 2019

This maybe the wrong place to post this but not sure where else to post. Is it currently possible to set a static ip for the WSL2 machine?

I'm loving WSL2 so far with docker and vscode and my only issue is dynamic ip at the moment.

@edwindijas
Copy link

@edwindijas edwindijas commented Jun 22, 2019

There is a work around. You can port forward to host ip.
Check the below link.
#4150

@zippaaa
Copy link

@zippaaa zippaaa commented Jun 22, 2019

I agree with the author of the question, please, Wsl2 must have option "static IP". Maybe cmd: wsl --ip <Distro> <IP address>?

@scrossan-crown
Copy link
Author

@scrossan-crown scrossan-crown commented Jun 24, 2019

My issue isn't just with port forwarding and docker. The biggest issue was that I am using VSCode remote development extension and remote developing in WSL and if I need to restart WSL2 to release some resources then I can't just reconnect in the usual way and any unsaved changes get lost which accidentally happened last week.

@MiklerGM
Copy link

@MiklerGM MiklerGM commented Jul 3, 2019

@alekseymvt
You could execute any command using wsl like this

wsl -- ifconfig eth0

@yanyan33333
Copy link

@yanyan33333 yanyan33333 commented Jul 13, 2019

Any solution?
also see MicrosoftDocs/WSL#418 (comment)

The Hyper-V Switch IP change everytime when the windows reboot, so the gateway in wsl 2 also need to change

@Ghostaunt
Copy link

@Ghostaunt Ghostaunt commented Aug 1, 2019

Looking for a solution too :)

@MiklerGM
Copy link

@MiklerGM MiklerGM commented Aug 1, 2019

With the latest update, you can access remote ports(WSL2) as local on Windows Host

You can have a look at this Windows Service - assign a static hostname for WSL machine

@zippaaa
Copy link

@zippaaa zippaaa commented Aug 1, 2019

With the latest update, you can access remote ports(WSL2) as local on Windows Host

Can anybody check?:
Will "http://mysite" work too, if I add "127.0.0.1 mysite" in "windows/hosts"? or localhost only?

@MiklerGM
Copy link

@MiklerGM MiklerGM commented Aug 1, 2019

Yes, it should work

@scrossan-crown
Copy link
Author

@scrossan-crown scrossan-crown commented Aug 1, 2019

It would be nice but instead of WSL 2 ports being bound to 127.0.0.1 they are bound to ::1 and that doesn't work in the browser or hosts file. So we got localhost support but not in a way we can map other domains to it.

@moigagoo
Copy link

@moigagoo moigagoo commented Aug 1, 2019

@MiklerGM

Yes, it should work

It doesn't, unfortunately. To point a custom domain to WSL, I'm adding a line like 172.25.203.130 mysite.com, where 172.25.203.130 is the IP of eth0 interface of the WSL VM: ip addr show eth0 | grep 'inet\b' | awk '{print $2}' | cut -d/ -f1

@MiklerGM
Copy link

@MiklerGM MiklerGM commented Aug 1, 2019

@moigagoo check out this https://github.com/shayne/go-wsl2-host you can do it automatically with this service

@moigagoo
Copy link

@moigagoo moigagoo commented Aug 1, 2019

@MiklerGM Thanks, I've seen it. I'm OK with my own self-written script.

@MiklerGM
Copy link

@MiklerGM MiklerGM commented Aug 1, 2019

btw, I have no problem accessing the custom domain, for example, test.com from my browser
My hosts file on Windows host machine

127.0.0.1 localhost api db test.com
172.20.124.104 wsl.local

image

@moigagoo
Copy link

@moigagoo moigagoo commented Aug 1, 2019

@MiklerGM Huh, that's interesting. Tried that several times, it never worked, adn still doesn't 🤔

It works even if you remove the last line, doesn't it? Maybe, you did something else apart from editing hosts file, like installed something like dnsmasq? Also, maybe this Go service does more than just writes to hosts?

@yanyan33333
Copy link

@yanyan33333 yanyan33333 commented Aug 1, 2019

maybe build 18945
https://devblogs.microsoft.com/commandline/whats-new-for-wsl-in-insiders-preview-build-18945/

@scrossan-crown
Copy link
Author

@scrossan-crown scrossan-crown commented Aug 1, 2019

@yanyan33333 I'm already on build 18945 but still no joy

image

@Ghostaunt
Copy link

@Ghostaunt Ghostaunt commented Aug 1, 2019

With the latest update, you can access remote ports(WSL2) as local on Windows Host

Can anybody check?:
Will "http://mysite" work too, if I add "127.0.0.1 mysite" in "windows/hosts"? or localhost only?

Yes, it should work

I confirm it doesn't work.
I would add my custom domain with 127.0.0.1 but doesn't work when I try to access with this domain.
localhost work, but not custom hosts

@scrossan-crown
Copy link
Author

@scrossan-crown scrossan-crown commented Aug 1, 2019

One work around I've found is if you are using docker and you install the latest edge version. It has support for WSL2 and it uses some magic (not sure what it's doing) but now 127.0.0.1 is working for in my hosts file for the apps in my docker containers on WSL2.

@yanyan33333
Copy link

@yanyan33333 yanyan33333 commented Aug 2, 2019

@scrossan-crown it works ,I start nginx on wsl and I can visit the website in windows brower by using localhost

@scrossan-crown
Copy link
Author

@scrossan-crown scrossan-crown commented Aug 2, 2019

@yanyan33333 I can do the same but can't use 127.0.0.1 in my hosts file with a domain name and access my docker container running on port 80 but I can now that I'm using docker desktop edge version

@zippaaa
Copy link

@zippaaa zippaaa commented Aug 2, 2019

@yanyan33333

I start nginx on wsl and I can visit the website in windows brower by using localhost

Check custom domain:
WSL2
/etc/nginx/conf.d/mysite.conf ->

server {
    server_name mysite;
    listen 80;
    ...
}

Windows
hosts -> 127.0.0.1 mysite -> http://mysite

@MiklerGM
Copy link

@MiklerGM MiklerGM commented Aug 2, 2019

@alekseymvt it is working for me
image

I do not have dnsmasq, but I've got service in Go (I should've removed it by now), and a started systemd service. /etc/hosts on my WSL and windows systems are in sync, I did not change anything on WSL.

From my knowledge, this should not affect the GET requests. You can even send GET request via telnet. The domain in your browser's address bar only represents the HTTP Header for HOST directive.

Steps to debug

  • Check that nginx is working correctly on WSL (with all your domains and server_names)
  • Check if windows resolve your hosts correctly.
  • Check windows build number >18945.1001
  • Send the GET request to nginx

In case it is not working

  • Check that nothing is listening to 80 port on your host system or change the nginx port

@zippaaa
Copy link

@zippaaa zippaaa commented Aug 2, 2019

@MiklerGM

it is working for me

Thank you, I saw your answer. I answered to @yanyan33333, because he wrote about localhost.
I will check a custom domain later for myself, I need download 3Gb :)

@craigloewen-msft
Copy link
Member

@craigloewen-msft craigloewen-msft commented Aug 7, 2019

We also had a bug where you needed to bind your Linux applications to 0.0.0.0 instead of 127.0.0.1 to access it, which we've fixed. This is being tracked in issue #4353

@webfaqtory
Copy link

@webfaqtory webfaqtory commented Aug 19, 2019

On build 18963 I can access http://localhost fine but in my Windows host file I have defined domains:
127.0.0.1 www.tripal.john
127.0.0.1 www.tripal3.john
127.0.0.1 clean.tripal3.john
These refuse to connect. Even added them to /etc/hosts. No joy

@sth4me
Copy link

@sth4me sth4me commented Aug 29, 2019

Set 127.0.0.1 domain in Windows hosts file does not work all the time,even only do nothing.
File I/O in /mnt is slow, so I put my project files in ~/, then IDE should use them by sftp. But when sftp connect for a while, all connections by hosts file will fail.
I use script change hosts file ip to wsl ip, and let project files in /mnt, it works well.
Static IP may be better.

@jdsdc
Copy link

@jdsdc jdsdc commented Aug 20, 2021

For me if I do as suggested in #4210 (comment) then I have to repair my network settings as all communications to my Physical network are lost. For me adding an external network to a Hyper-V client messes things up and I don't know why,

Also, the solution here #4210 (comment). How does that work. With the an IP of 0.0.0.0?

As per a previous suggestion. Put the last two lines in a command/bat script and run as a administrator.
Adjust Linux distribution if other, list distritbutions:

wsl -l

Access wsl: 192.168.99.2 Access Host: 192.168.99.1

netsh interface ip add address "vEthernet (WSL)" 192.168.99.1 255.255.255.0

wsl -d Ubuntu-20.04 -u root ip addr add 192.168.99.2/24 broadcast 192.168.99.255 dev eth0 label eth0:1;

@osmboy
Copy link

@osmboy osmboy commented Aug 22, 2021

sometimes @hez2010 script not work after system reboot, My solution is, save the script with wsl2_static_ip.bat file

@echo off
wsl -d ubuntu2004 -u root ip addr del $(ip addr show eth0 ^| grep 'inet\b' ^| awk '{print $2}' ^| head -n 1) dev eth0
wsl -d ubuntu2004 -u root ip addr add 192.168.50.2/24 broadcast 192.168.50.255 dev eth0
wsl -d ubuntu2004 -u root ip route add 0.0.0.0/0 via 192.168.50.1 dev eth0
wsl -d ubuntu2004 -u root echo nameserver 192.168.50.1 ^> /etc/resolv.conf
powershell -c "Get-NetAdapter 'vEthernet (WSL)' | Get-NetIPAddress | Remove-NetIPAddress -Confirm:$False; New-NetIPAddress -IPAddress 192.168.50.1 -PrefixLength 24 -InterfaceAlias 'vEthernet (WSL)'; Get-NetNat | ? Name -Eq WSLNat | Remove-NetNat -Confirm:$False; New-NetNat -Name WSLNat -InternalIPInterfaceAddressPrefix 192.168.50.0/24;"
exit

and add simple check static ip in your ~/.bashrc or ~/.zshrc

if [ `hostname -I` != 192.168.50.2 ]; then
        cmd.exe /c "D:\wsl2\wsl2_static_ip.bat" 1>nul
fi

this always works in my environment
Other than that,the Windows Firewall is blocking wsl2 traffic, you need to create a new rule. the operation is as follows:

New rule->Rule type: Custom->Program: All programs->Protocol and port: Any->Scope: Add remote ip address: 192.168.50.0/24->
action: allow connection->profile: select all->name wsl2 -> click ok

then your wsl2 has both a static address and access to the internet

@leecholho
Copy link

@leecholho leecholho commented Sep 4, 2021

and add simple check static ip in your ~/.bashrc or ~/.zshrc

if [ `hostname -I` != 192.168.50.2 ]; then
        cmd.exe /c "D:\wsl2\wsl2_static_ip.bat" 1>nul
fi

When I try to run C: \ wsl2_static_ip.bat on the host in the .bashrc of the user on the wsl2 side,
The following "Access is denied" is displayed.
Are there any settings that are missing?

'\\wsl$\Ubuntu-20.04\home\dev4docker'
CMD.EXE was started with the above path as the current directory.
UNC paths are not supported.  Defaulting to Windows directory.
Remove-NetIPAddress : Access is denied.
At line:1 char:55
+ ... SL)' | Get-NetIPAddress | Remove-NetIPAddress -Confirm:$False; New-Ne ...
+                               ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : PermissionDenied: (MSFT_NetIPAddre...ystemName = ""):ROOT/StandardCimv2/MSFT_NetIPAddres
   s) [Remove-NetIPAddress], CimException
    + FullyQualifiedErrorId : Windows System Error 5,Remove-NetIPAddress

Remove-NetIPAddress : Access is denied.
At line:1 char:55
+ ... SL)' | Get-NetIPAddress | Remove-NetIPAddress -Confirm:$False; New-Ne ...
+                               ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : PermissionDenied: (MSFT_NetIPAddre...ystemName = ""):ROOT/StandardCimv2/MSFT_NetIPAddres
   s) [Remove-NetIPAddress], CimException
    + FullyQualifiedErrorId : Windows System Error 5,Remove-NetIPAddress

New-NetIPAddress : Access is denied.
At line:1 char:92
+ ... irm:$False; New-NetIPAddress -IPAddress 192.168.50.1 -PrefixLength 24 ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : PermissionDenied: (MSFT_NetIPAddress:ROOT/StandardCimv2/MSFT_NetIPAddress) [New-NetIPAdd
   ress], CimException
    + FullyQualifiedErrorId : Windows System Error 5,New-NetIPAddress

New-NetNat : Failed to start WinNAT service
At line:1 char:249
+ ... irm:$False; New-NetNat -Name WSLNat -InternalIPInterfaceAddressPrefix ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : PermissionDenied: (MSFT_NetNat:root/StandardCimv2/MSFT_NetNat) [New-NetNat], CimExceptio
   n
    + FullyQualifiedErrorId : Windows System Error 5,New-NetNat

@Biswa96
Copy link

@Biswa96 Biswa96 commented Sep 5, 2021

I have a workaround here #7395

@hez2010
Copy link

@hez2010 hez2010 commented Sep 5, 2021

@leecholho wsl2_static_ip.bat need to be run as administrator

@leecholho
Copy link

@leecholho leecholho commented Sep 6, 2021

I gave up calling from wsl linux.
Instead, after starting wsl, run the bat file manually with administrator privileges.

@MahbbRah
Copy link

@MahbbRah MahbbRah commented Sep 19, 2021

@leecholho wsl2_static_ip.bat need to be run as administrator

I was trying to run that bat file but it threw error

The syntax of the command is incorrect. C:\Users\lucka\Downloads>#include <windows.h>

was trying to run that file directly from CMD with administrative access.

@aleneum
Copy link

@aleneum aleneum commented Oct 15, 2021

As mentioned earlier, wsl2_static_ip.bat needs administrative privileges. You can add this to your .bashrc and it will ask for elevation when needed. Just replace ${WSL_IP} and ${WIN_SCRIPT_PATH} with what you need. For instance, if you use the script as it was posted above, WSL_IP would be 192.168.50.2

if [ `hostname -I` != ${WSL_IP} ]; then
    /mnt/c/Windows/system32/WindowsPowerShell/v1.0/powershell.exe -Command "Start-Process cmd.exe -Verb RunAs -ArgumentList {/c ${WIN_SCRIPT_PATH}\wsl2_static_ip.bat}"
fi

@Genda1ph
Copy link

@Genda1ph Genda1ph commented Oct 20, 2021

Just to recap: all of this stems from our inability to tell WSL2 not to mess with Hyper-V networking and allow us to handle networking ourselves.

I am running Hyper-V on my machine, with a bridged interface (br0), so unless I change br0 to Internal or Private mode, this WSL switch trick doesn't work.
On top of that, I can't rely on WSL switch being present for other VMs, since it seems to be dynamically created and changed on every reboot.
On top of that, WSL2 doesn't have an easy way of running something on startup. I tried upgrading my Debian from WSL1 to WSL2 - it's running /init instead of systemd or something I can mess with, and setting a boot command in /etc/wsl.conf runs it before network interfaces are in.
...so my best bet is stuffing network config script into ~/.profile or something - did I read this right?

@aki-k
Copy link

@aki-k aki-k commented Oct 20, 2021

On top of that, WSL2 doesn't have an easy way of running something on startup. I tried upgrading my Debian from WSL1 to WSL2 - it's running /init instead of systemd

You can enable systemd in WSL 2 with this script:

https://github.com/damiongans/ubuntu-wsl2-systemd-script

Clone that repository on the Windows host side, then change basic.target to multi-user.target in start-systemd-namespace and enter-systemd-namespace. To enable systemd in WSL 2, run "bash ubuntu-wsl2-systemd-script.sh" on the Windows host side. The next time you run bash, it'll show a line about enabling systemd. After this run "sudo systemctl set-default multi-user.target" in WSL 2.

@hez2010
Copy link

@hez2010 hez2010 commented Oct 20, 2021

On top of that, WSL2 doesn't have an easy way of running something on startup. I tried upgrading my Debian from WSL1 to WSL2 - it's running /init instead of systemd or something I can mess with, and setting a boot command in /etc/wsl.conf runs it before network interfaces are in.

@Genda1ph Use genie for systemd support.

@LordFPL
Copy link

@LordFPL LordFPL commented Oct 20, 2021

As commented on #4210 (comment) i would recomment this solution for ip problem (https://github.com/shayne/go-wsl2-host). An official Microsoft solution will be better... but while it's happen, it works.
And for systemd support, i have try genie and other things... IMHO simple is better, and again, Shayne solution is much better : https://github.com/shayne/wsl2-hacks

@Genda1ph
Copy link

@Genda1ph Genda1ph commented Oct 21, 2021

You're missing the whole point: for this to properly work alongside Hyper-V, I need a second NIC: one for Hyper-V bridge/switch and one for WSL bridge/switch. You literally cannot run one NIC in 2 Hyper-V switches.

Ty @hez2010, genie does look like somewhat viable solution, if WSL didn't mess with network to this extent.

@mrkanaly
Copy link

@mrkanaly mrkanaly commented Oct 21, 2021

@jgregmac has updated his solution using the work done by @skorhone. It provides a script to install a logon event that will re-create the WSL switch in your preferred location every time at boot. Recommend checking it out.

https://github.com/jgregmac/hyperv-fix-for-devs

@Genda1ph
Copy link

@Genda1ph Genda1ph commented Oct 21, 2021

@mrkanaly that's not the issue I'm facing.
I'm running this in a home network, and WSL is a convenient way to back my files up using rsync. All WSL1 needed for this to work was to configure and run sshd. WSL2 makes this simple task a major pain:

  • I either need to port-forward to WSL
  • or configure WSL switch to be public, which conflicts with my Hyper-V switch (physical NIC can't be attached to more than one switch)
  • I can't use my existing Hyper-V switch for WSL

On top of this, the simplest way to set up static IP for WSL2 is to run a script on WSL startup, which is also a pain in current stable release, but should be easier when boot command gets to me.

If I could just tell WSL not to mess with setting up network and just attach the VM to an existing Hyper-V switch and run a script on startup - I would be golden, but instead I have to pile workarounds on top of workarounds for this to work. There are use-cases for this scenario, and I'm not the only one with this issue.

But at this point I gave up waiting for MS to fix WLS2 networking and currently playing with Ansible to set up a Hyper-V VM to fulfill my needs.

@skorhone
Copy link

@skorhone skorhone commented Oct 21, 2021

The underlying issue is that wsl2 network is using host compute network (hcn) not hyper-v switches. The main difference between the two seems to be that hcn does not persist configuration.

While I have zero evidence, I have a feeling that hcn operates on same low level proprietary apis that hyper-v does. Hyper-v layer just adds persistence and management UIs on top of this. Hcn has relation to hcs (host compute system) which is an api that allows third parties to create their own virtualization solutions on top of windows virtualization platform. Not all these third party solutions require persistence, so it's actually a good design decision that hcn leaves responsibility to caller.

For majority of home users not persisting network configuration is a good choice. If something goes wrong in network configuration, reboot solves the issue.

Sadly majority of home users is not majority of wsl2 users. There's a huge potential in enterprise sector for this (all software developers using windows are potential users) In enterprise environment not being able to define (persist) network configuration is just an awful choice.

@ocroz
Copy link

@ocroz ocroz commented Oct 22, 2021

I have pushed a wsl-boot solution that allows to:

  • Set a static IP to the WSL2 machine,
  • Connect it to other VMs (all having their own static IP in the same internal subnet as WSL2),
  • Provide the network access of the host to WSL2 and all other VMs,
  • Delete all NAT networks but WSL one,
  • Adapt the DNS nameserver on WSL2 depending on how you are connected via VPN or not,
  • Start ssh daemon on WSL2 so you can connect from GitBash too.

Please check out: https://github.com/ocroz/wsl2-boot.

@ocroz
Copy link

@ocroz ocroz commented Oct 22, 2021

I just tested the solution hyperv-fix-for-devs of @jgregmac (re-using the work of @skorhone) and it works nice to create the missing NetAdapter on Windows startup. This fixes the Windows part in a much better way. Thanks you for the tip.

It even fixes the problem I had with DNS so we can use the IP gateway e.g. 192.168.50.1 everywhere in WSL2 and all other VMs connected to the same Virtual switch WSL. The only problem I have now is because the Virtual switch WSL is deleted on Windows shut down, before to start my VM in Hyper-V, I must fix the configuration error and select the new created Virtual switch WSL again.

My solution wsl2-boot is derived from #4210 (comment).

Having a boot script such as /boot/wsl-boot.sh is still nice because we can start anything here, and even start the cron service so that the main script returns immediately while cron continues to run other @reboot commands.

So once we installed hyperv-fix-for-devs*, to startup WSL2 with fixed IP, we can open a normal PowerShell prompt (not as Administrator anymore) and run: wsl -u root /boot/wsl-boot.sh.
* To make it work, I had to remove the NAT network I created previously: Remove-NetNat -Name WSLNat.

@wikiped
Copy link

@wikiped wikiped commented Oct 22, 2021

WSL-IpHandler is an alternative solution which puts together some of the approaches posted here in a single Powershell module. It allows to control both a deterministic SubNet and a static IP addresses for WSL instances.

@ocroz
Copy link

@ocroz ocroz commented Nov 2, 2021

Now with wsl2-boot, the unique command wsl-boot starts everything cleanly and completely, including the connected VMs.

@Genda1ph
Copy link

@Genda1ph Genda1ph commented Nov 7, 2021

@skorhone I confirmed that bridging WSL and actual physical port breaks networking upon reboot.
So you have to UN-bridge WSL before rebooting, or you'll be stuck with an interface that is bridged to a no longer existing vSwitch, and thus cannot be bridged again.

@ikechukwukalu
Copy link

@ikechukwukalu ikechukwukalu commented Jan 16, 2022

What worked for me was to give wsl a domain within my host file and run a PowerShell script on startup which will update the wsl IP every time.

With this approach, it's also possible that after you have configured apache and Nginx within your wsl, you can also assign them a port and static IP using PowerShell as well, from which you can now run multiple apps on your apache and Nginx over their respective static IPs, but each with their unique domain names.

You can find the solution over here:
https://superuser.com/a/1685919/1065065

@JSimo
Copy link

@JSimo JSimo commented Jan 17, 2022

Had a similar issue related to needing something like this. WSL kept either picking an IP in 192.168 or 172.
The problem is that due to reasons I require WSL to run in 172.x.

Based on the solutions above I made a pure bash solution (which calls powershell as needed).
solution:

#!/bin/bash

# Fix network adapter in WSL
sudo ip addr del $(ip addr show eth0 | grep "inet\b" | awk '{print $2}' | head -n 1) dev eth0
sudo ip addr add 172.21.199.208/20 broadcast 172.21.207.255 dev eth0
sudo ip route add 0.0.0.0/0 via 172.21.192.1 dev eth0

# Fix network adapter configuration in windows
powershell.exe Start-Process -Verb runas powershell.exe -ArgumentList \'$(echo '-noexit -c Get-NetAdapter \"vEthernet (WSL)\" | Get-NetIPAddress | Remove-NetIPAddress -Confirm:$False; New-NetIPAddress -IPAddress 172.21.192.1 -PrefixLength 20 -InterfaceAlias \"vEthernet (WSL)\"; Get-NetNat | ? Name -Eq WSLNat | Remove-NetNat -Confirm:$False; New-NetNat -Name WSLNat -InternalIPInterfaceAddressPrefix 172.21.192.0/20;')\'

# SUPER OPTIONAL: Update display (may be different on your machine!)
export DISPLAY=$(ip route | awk '/^default/{print $3; exit}'):0

edit: 2022-03-14: updated to remove \ before Confirm:\$False
edit: 2022-03-14: added note about needing to update the $DISPLAY variable

@obriat
Copy link

@obriat obriat commented Mar 14, 2022

@JSimo : your script doesn't work on my machine, I got powershell errors about Confirm:$False (I don't remember if the \ is missing or not required).
Even if I run the powsershell part manually I can't access my docker container with the declared IP

@JSimo
Copy link

@JSimo JSimo commented Mar 14, 2022

@JSimo : your script doesn't work on my machine, I got powershell errors about Confirm:$False (I don't remember if the \ is missing or not required). Even if I run the powsershell part manually I can't access my docker container with the declared IP

Thanks for noticing! You are correct, I've ran into this syntax error last week when I ran into the issue again (Very rare to run into this issue). Updated the script in my comment.

Also added another note, about fixing the $DISPLAY after running the script, as using this together with xserver is my primary purpose.


Also the script comes with 0 guarantees about conflicting IP addresses. It essentially just tries to hard-set it to 172.21.199.208 including routing. If that is not an ip you want to use, you need to update the script.

@Mira43
Copy link

@Mira43 Mira43 commented Apr 28, 2022

As mentionned in #4210 (comment), using ::1 instead of 127.0.0.1 in your hosts file works to reach a domain in my side (I am on windows 11).
So in my opinion, no need to other software for this workaround.

Example if you want to reach myapp.test :
Add into windows hosts files AND your wsl instance hosts file :
::1 myapp.test

By this way, your are not dependant of each IP change of your wsl instance

@hatakawas
Copy link

@hatakawas hatakawas commented Jun 20, 2022

Now with wsl2-boot, the unique command wsl-boot starts everything cleanly and completely, including the connected VMs.

looks like a great project, but the INSTALL guide is too confused for me..lol

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests