-
Notifications
You must be signed in to change notification settings - Fork 822
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
[WSL 2] NIC Bridge mode 🖧 (Has TCP Workaround🔨) #4150
Comments
Same issue here. IP address of Windows machine is 192.168.1.95 and the eth0 interface in Ubuntu on WSL2 is getting 172.18.47.17. I originally had Ubuntu on WSL1 running and then upgraded the installation to WSL2 but same problem. Then I uninstalled Ubuntu altogether and reinstalled fresh but same issue after reinstall. Prior to using WSL2 I had an instance of Ubuntu setup as a Hyper-V VM on the same machine (Hyper-V NIC bridge already existed). |
Same issue. I have a rstudio server running in docker container in WSL2 and wanted to access it from other machine but failed. Really need some fix/idea on it. |
I can confirm this issue. |
It's not a bug with WSL 2, WSL 2 is running as a hyper-v virtual machine. The hyper-v adapter can be found in network adapters. You can use port forwarding to forward the port with netsh as below. |
Hi! Did you try it on your end? It didn't work for me when I was trying to access it from another machine in the same network. Although I did work when I use the windows host. |
I tried it. It worked but the craziest thing is happening, the ip address is changing on reboot. Don't forget to add inbound and outbound rules. Microsoft will fix this issue in the future |
WSL 2 TPC NETWORK FORWARDINGIntroduction With the introduction of WSL 2 Beta, Microsoft has made changes to the system architecture. The work around is to use a script that does :
Configuration The script must be run at login ,under highest privileges to work, and Powershell must be allowed to run external sources. PowerShell Configuration Enable power shell to run external scripts, run the command below in power shell with administrative privileges. How To: Finally: Update
|
@edwindijas Awesome, that worked for me! 👍 🎉 I can access my running Linux service from any system on my network via my Windows host IP! In addition, this workaround means I was trying to go down another route by forcing bridge mode of WSL virtual adapter, that didn't work. Just including it here for completeness. PS C:\WINDOWS\system32> Set-VMSwitch WSL -NetAdapterName 'Name_of_your_phsyical_windows_NIC'
Set-VMSwitch : Failed while adding virtual Ethernet switch connections.
External Ethernet adapter 'Name_of_your_phsyical_windows_NIC' is already bound to the Microsoft Virtual Switch
protocol.
At line:1 char:1
+ Set-VMSwitch WSL -NetAdapterName 'Name_of_your_phsyical_windows_NIC'
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Set-VMSwitch], VirtualizationException
+ FullyQualifiedErrorId : InvalidParameter,Microsoft.HyperV.PowerShell.Commands.SetVMSwitch @edwindijas Linked your comment as a workaround for this issue in my original post #4150 (comment). |
The script only opens ports you desired. And the ports are redirected to WSL machine. |
my method to solve this problem: refresh ip in win10:hosts file |
I saved your script in a file called "wslbridge.ps1" and then in Windows Scheduler just set Powershell.exe as Action and as argument I wrote this (instead of setting the Unrestricted ExecutionPolicy): Thanks |
I wrote a Windows Service that automatically writes the WSL2 VM's IP address to the Windows hosts file. You can then just always reference "wsl.local" from your host machine and it will resolve to the WSL2 VM. I've been using this for a week now and just open-sourced it. |
I've collected a few WSL2 hacks into a repo: One thing I wanted to point out, relevant to this thread, was "Access localhost ports from Windows", a way to access ports bound to |
Thanks @edwindijas, it is a great workaround. For people using Debian, which does not come with
Also, the hint from @gstorelli of using Thanks, guys! |
If there are multi wsl2 in your system, remember use this command on cmd to change the wsl2 which you want to bind these port as the default one, because bash.exe will run command in the default wsl2 environment:
|
@edwindijas I was hoping to make my Google Chrome (inside my Kali Distro) recognize my Chromecast, but i couldn't find anywhere the actual ports chromecast uses to connect, however now i can access my Kali from anywhere trought SSH. |
You can now use localhost to connect in recent WSL2 versions |
That's really sort of a different problem -- you can use "localhost" from the host itself, but there's no obvious way to get there from a different machine on the network: WSL2 is running on Windows host A |
If you open the port, why would you not be able to connect to host A from host C by just doing "host-A-ip:port"? This behaviour shouldn't be any different then it is for linux. |
I don't know the technical reason for it, but it doesn't work by default, and is what brought me here. |
Although you can open Win app by localhost:port from WSL2, but they are definitely not sharing the same network like WSL1. This is working in WSL1, but in WSL2 it's not. Still waiting form a solution. |
See above. |
I have reinstalled windows 11 and needed to re-setup WSL with all new bells and whistles.
https://github.com/pawelgnatowski/WSL2-Network-Fix now i can expose my containers to the internet. |
@pawelgnatowski I recently installed a fresh W11 system with WSL2, and it just works out of the box. Mirror mode completely breaks networking for WSL2 for me, though. It could be something in docker that is attaching it, though, I haven't tried directly connecting to a service running in the bare wsl2. |
Me, along with 341 more people learned that WSL actually stands for macos inside windows :v @pawelgnatowski @ericblade You don't need to use custom scripts anymore. Just use the "bridged" network mode. Create a new hyper-v switch and set it in Here is my config for reference. .wslconfig[wsl2]
kernelCommandLine=ipv6.disable=1
memory=16GB
swap=0
guiApplications=true
debugConsole=false
#vmIdleTimeout=-1
networkingMode=bridged
vmSwitch=WSLBridged
dhcp=false
macAddress=0E:00:00:00:00:00
ipv6=false
[experimental]
autoMemoryReclaim=gradual And inside ubuntu distro:/etc/wsl.conf[user]
default=gittu
[boot]
systemd=true
[network]
hostname = GITTUW11WSL
generateResolvConf=false /etc/systemd/network/20-wslbridged.network[Match]
Name=eth0
[Network]
Description=WSLBridged
DHCP=yes NB: ipv6 is disabled in both wsl and in ubuntu because of #4851. |
@sarim i haven't had to do any of that anymore to get it to bridge. i wish we had host support now, though. :D |
Seems like a good place to ask. I have this config:
Mirrored mode is another potential solution, but I'm not ready to try it yet. Anything else I can do to get VSCode integration and filesystem access back? [UPDATE] |
@pbasov local port forwarding works for me with my bridged configuration. Try to replicate my settings #4150 (comment) and see if it works. |
@sarim i used your solution & got this when i tried to do
Note: I haven't restarted my PC but I used |
@deadcoder0904 You have to create a hyper-v bridge named |
@sarim i tried your suggestion. i first installed & enabled hyper-v using this video & then i tried to follow this guide. i'm stuck at the last 2 steps. what they show: what i see: how do i find a virtual machine? i tried solutions here but no luck. i'm assuming this should point to wsl2 but how would i do it? is it import? would love a suggestion. |
@deadcoder0904 It is not related to virtual machines. You have to click "Virtual Switch Manager" in the right sidebar. Detailed tutorial is somewhere in this thread buried deep. |
@sarim i did exactly that. the guide i linked above (2nd link) but i don't see a virtual machine. idk if that step (like seeing a virtual machine) is necessary. i'll try it again sometime. for now, changing |
alright, so this solution (read the comments below that) is much better. i only have to change |
Simply put, thanks for the inspiration – The ultimate recipe https://github.com/Unsigned-Char/WSL2HyperVSwitch |
Here a detailed working procedure on how to use WSLAttachSwitch Script : #4799 (comment) Text : #4799 (comment) |
How I made WSL2 use the external LAN interface: |
@salimmj In Windows Server 2025 with the following info:
The networkingMode=bridged is not working. You can enable it in .wslconfig but the interface can not obtain any IP actually. |
Hi, |
To set the IP I have the below commands that runs whenever WSL2 is loged on: sudo ip addr flush dev eth0 And whenever WSL2 is logged on it re-sets the IP to 192.168.169.154 Of course you must use Ips that are in your subnet and use proper ethernet name if eth0 is not correct. |
I really love the Dynamic-Wallpaper software. If there were a Windows or Linux version, I would be willing to purchase it for a lifetime. |
I really love the Dynamic-Wallpaper software. If there were a Windows or Linux version, I would be willing to purchase it for a lifetime. |
Instead of working on a project I am fighting with this 💩. Seriously MS, since 2019! Dual-boot Linux for me that is... |
@young03600 Outbound rules are required because otherwise your server would not have a way to serve whatever it serves to the outside network. Here's a tool I created to deal with all of this automatically. You can use it like this: |
What about WSL-Distro1 to WSL-Distro2 Networking/Connections? |
Issue
WSL 2 seems to NAT it's virtual network, instead of making it bridged to the host NIC. My goal is for a service running in Ubuntu in WSL 2 to be accessible from anywhere on my local network.
Issue Details
Your Windows build number:
Microsoft Windows [Version 10.0.18917.1000]
What you're doing and what's happening:
Running
ipconfig
on my Windows 10 host machineRunning
ifconfig
in Ubuntu WSL 2Accessing 172.18.72.60 from my Window host does work, however this IP is not accessible from another system on my network.
What's wrong / what should be happening instead:
I would expect to
ifconfig
in Ubuntu WSL 2 to have an IP address in the same network as my host machine.Searching the docs:
The only detail I have found about WSL 2 networking is the following that notes that it will have it's own IP and that localhost is something that will be used for WSL 2 in the future.
https://docs.microsoft.com/en-us/windows/wsl/wsl2-ux-changes
This is fine, however I would like the IP WSL 2 is getting to be on my local LAN which means I need to configure the virtual NIC to be bridged.
Workaround
See @edwindijas #4150 (comment)
The text was updated successfully, but these errors were encountered: