-
Notifications
You must be signed in to change notification settings - Fork 840
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. |
@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 |
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? |
Nearly 2025 and this is the only working solution! |
There is a solution to expose on the LAN an IP address tied directly to the WSL2 guest operating system, even in Windows 10 where WSL2 does not support |
From just released v2.4.5 changelog
Umm is the bridged networking mode going away? That would be a huge dealbreaker. Would love some official info on that. I recognize current bridged networking implementation is not polished/user-friendly for novice users but for me personally (and my estimation is with experienced linux sysadmin / virtualization experts) it's not unusable, it works. I understand the pitfalls of attaching bridged switch to the master VM, and its okey for my use case. |
Please hope not. Bridged mode works very well as it is now. WSL2 bridged is the only option that works with docker network host as expected. |
Doesn’t Microsoft have a contact page where I can ask for a reason behind removing a Windows feature?What would be a good reason to remove bridged networking mode? I don’t want just any reason, but a GOOD reason. Don’t get me wrong, I want to know Microsoft’s motivation behind removing bridged networking mode.What is a good reason for Microsoft to make WSL network an ephemeral network that is deleted as soon as I shut down or reboot Windows, and not a persistent network? What is a good reason for Microsoft to not just use the “default switch”? I do want Microsoft’s motivation behind that design, but I also want a GOOD reason. Anyway, why would Microsoft not want communication between WSL instances and Hyper-V guests?Sent from my iPadOn Dec 4, 2024, at 7:35 AM, Bernd Eichelberger ***@***.***> wrote:
From just released v2.4.5 changelog
Add user warning letting users know bridged networking will be deprecated
Umm is the bridged networking mode going away? That would be a huge dealbreaker. Would love some official info on that.
Please hope not. Bridged mode works very well as it is now. WSL2 bridged is the only option that works with docker network host as expected.
—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you commented.Message ID: ***@***.***>
|
Bridging NAT is complicated, you can't use tools like DHCP server and port
mirroring easily. But there are probably more selfish reasons like not
wanting to handle an extra layer. But you can put NAT on linux:
https://linuxhint.com/configure-nat-on-ubuntu/ and manage it yourself. I've
seen the need for IPV4 for Netflix to tunnel on IPV6 networks for instance
(this also required isc-dhcp-client updates). Good luck.
…On Wed, Dec 4, 2024 at 4:15 PM Verld ***@***.***> wrote:
Doesn’t Microsoft have a contact page where I can ask for a reason behind
removing a Windows feature?What would be a good reason to remove bridged
networking mode? I don’t want just any reason, but a GOOD reason. Don’t get
me wrong, I want to know Microsoft’s motivation behind removing bridged
networking mode.What is a good reason for Microsoft to make WSL network an
ephemeral network that is deleted as soon as I shut down or reboot Windows,
and not a persistent network? What is a good reason for Microsoft to not
just use the “default switch”? I do want Microsoft’s motivation behind that
design, but I also want a GOOD reason. Anyway, why would Microsoft not want
communication between WSL instances and Hyper-V guests?Sent from my iPadOn
Dec 4, 2024, at 7:35 AM, Bernd Eichelberger ***@***.***> wrote:
From just released v2.4.5 changelog
Add user warning letting users know bridged networking will be deprecated
Umm is the bridged networking mode going away? That would be a huge
dealbreaker. Would love some official info on that.
Please hope not. Bridged mode works very well as it is now. WSL2 bridged
is the only option that works with docker network host as expected.
—Reply to this email directly, view it on GitHub, or unsubscribe.You are
receiving this because you commented.Message ID: ***@***.***>
—
Reply to this email directly, view it on GitHub
<#4150 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AEBBAQ74P6RPV3BLGEKB4HT2D6EIDAVCNFSM4HYQEW5KU5DIOJSWCZC7NNSXTN2JONZXKZKDN5WW2ZLOOQ5TENJRHA3TIOBVGM3Q>
.
You are receiving this because you commented.Message ID:
***@***.***>
--
Rob
|
Using DHCP Server (pihole / dnsmasq) within WSL2 with Without bridged mode, all those would be no longer possible. |
Yes, WSL2 work's perfectly as NAT router, but only with Since this working feature is marked by deprecated notice, this won't work any more soon. Required us to go back from Subsystem (WSL2) to complete virtual machines, which is slower. |
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: