-
Notifications
You must be signed in to change notification settings - Fork 823
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
Can't ssh into wsl with networking mode mirrored #10597
Comments
I ran in to the same problem today. I kept the default ssh port set to 22.
also,
here are my uncommented params in
also,
and,
and finally, my
|
@nisarg-ujjainkar @joehays thanks for reporting the issue when mirrored mode is on, firewall is also on by default. and Hyper-V firewall is blocking inbound traffic by default Can you try adding a Hyper-V firewall rule to allow inbound traffic to WSL to the SSH port? You can run the command below in an admin powershell window New-NetFirewallHyperVRule -DisplayName "allow WSL ssh" -Direction Inbound -LocalPorts 22 -Action Allow |
@CatalinFetoiu So, I learned something very important. The Hyper-V firewall is independent/separate from the Windows firewall. I had disabled the Windows firewall with my initial testing but it did not make a difference. For posterity sake... this seems like a good starting point for those of us new to Hyper-V to learn from: https://learn.microsoft.com/en-us/powershell/module/netsecurity/?view=windowsserver2022-ps |
@joehays great to hear to problem was fixed one note regarding Hyper-V firewall - if you add a rule in the Windows firewall to allow inbound SSH traffic, the rule will be automatically migrated to Hyper-V firewall I am closing the issue |
@CatalinFetoiu thanks. That fixed it. However, I am a bit curious about how I can directly ssh into the wsl instance if both Windows and WSL are listening to the same port (this is why I had changed the port to 2222)? |
@nisarg-ujjainkar in mirrored mode, by default Windows and WSL can't listen to the same port at the same time. if you need Linux to open the same port as Windows in mirrored mode, you can use the "ignoredPorts" option in the wslconfig file (you can find more details at https://learn.microsoft.com/en-us/windows/wsl/wsl-config) However if you specify a port in the "ignoredPorts" setting, the Linux port can be accessed only from within Linux. For your usecase this won't work as you need the SSH port to be accessed from outside Linux. In this case you need to change the SSH port, as you already did. |
@CatalinFetoiu I had disabled Windows sshd service, and start sshd service in WSL. I can access by Even after firewall rule added by My |
@yunsii ssh localhost means communicating between Windows and Linux using 127.0.0.1. this works by default ssh 192.168.0.98 means communicating between Windows and Linux using a local IP assigned to Windows. for this to work, you need to set hostAddressLoopback=true in your .wslconfig file, then restart WSL and retry the scenario. you can see more details at https://learn.microsoft.com/en-us/windows/wsl/wsl-config the firewall rule you added is not needed for this to work |
@CatalinFetoiu I didn't notice this option |
@CatalinFetoiu Excuse me. I have encountered an issue and I'm not sure if it's related to this issue: After setting up mirroring in WSL, I use Node to listen on port 3000 for an HTTP service. My local machine's IP address is 192.168.6.228. However, when I try to access 192.168.6.228:3000 from another device in the LAN (my phone), I am unable to connect. I'm unsure if this is a bug or an intentional design. |
@Kutius can you try the running the following command in an elevated powershell, then try your scenario again? Inbound traffic from the LAN must be allowed by the WSL firewall (Hyper-V firewall) New-NetFirewallHyperVRule -DisplayName "allow port 3000 inbound" -Direction Inbound -LocalPorts 3000 -Action Allow |
@CatalinFetoiu Ok it work!!! Thanks so much!! |
@Kutius great to hear! you can look at the documentation at https://learn.microsoft.com/en-us/powershell/module/netsecurity/set-netfirewallhypervrule?view=windowsserver2022-ps and https://learn.microsoft.com/en-us/powershell/module/netsecurity/remove-netfirewallhypervrule?view=windowsserver2022-ps also note that if you add a rule to allow inbound port 3000 in the Windows firewall, a corresponding rule will also be created in the Hyper-V firewall. |
@CatalinFetoiu Thank u! And:
Do it mean if I allow all inbound port, Hyper-V would accept any port? If so, When I start the same node service to listen 3000 in Windows, Other devices in LAN can access it. Should the services in WSL should also be expected to be access as intended? |
@Kutius "Do it mean if I allow all inbound port, Hyper-V would accept any port?" if you allow all inbound ports on the Windows firewall, then yes Hyper-V firewall will allow inbound traffic on all those ports "If so, When I start the same node service to listen 3000 in Windows, Other devices in LAN can access it. Should the services in WSL should also be expected to be access as intended?" if Windows firewall allows inbound traffic to port 3000, then yes Hyper-V firewall will also allow inbound traffic to port 3000 Let me know if this answers your questions |
@CatalinFetoiu I really appreciate your patient assistance!! After conducting some testing, I used port 3001 this time because I had already allowed port 3000.
So I guess maybe this is a bug? This is my wslconifg:
|
@Kutius can you please open a new issue with those details and tag me there? |
@CatalinFetoiu ok. Thank u very much for the answers for me here :). |
I am trying this mode (mirrored), my local ip is 192.168.1.103 and I am connected through an OpenVPN to a remote network so my tun0 ip is 10.10.16.25. I tried establishing a hyperV firewall rules to allow traffic through this port, tried disabling both Windows and HyperV firewalls, tried connecting to VPN from inside WSL2 instance. Nothing seems to get me this call back inside WSL2... |
@rz1027 thanks for reaching out. can you please open a new issue with those details? are you trying to connect to your listener from outside your Windows machine? |
Sure! |
@rz1027 thanks! you can tag me in the new issue once you open it. do you see the same problem if you disconnect from your OpenVpn connection? We have seen some other issues recently with OpenVpn and mirrored mode |
In addition to specifying ports, windows Firewall also supports directly specifying exe to pass through the firewall, which means that all ports that exe listens to are allowed to pass through the firewall. I think the ncat.exe you use is like this, but the nc in wsl does not (and cannot) set it like this. |
Windows Version
Microsoft Windows [Version 10.0.22621.2361]
WSL Version
2.0.0
Are you using WSL 1 or WSL 2?
Kernel Version
5.15.123
Distro Version
Ubuntu 22.04
Other Software
No response
Repro Steps
Expected Behavior
I would expect the ssh connection to just work.
Actual Behavior
ssh complains that it cannot resolve the hostname.
Diagnostic Logs
No response
The text was updated successfully, but these errors were encountered: