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

Networking mirrored can't access to windows by 127.0.0.1:port with WSL2 #11312

Closed
1 of 2 tasks
msojocs opened this issue Mar 16, 2024 · 20 comments
Closed
1 of 2 tasks

Networking mirrored can't access to windows by 127.0.0.1:port with WSL2 #11312

msojocs opened this issue Mar 16, 2024 · 20 comments
Labels

Comments

@msojocs
Copy link

msojocs commented Mar 16, 2024

Windows Version

Microsoft Windows [版本 10.0.22631.3296]

WSL Version

2.1.5.0

Are you using WSL 1 or WSL 2?

  • WSL 2
  • WSL 1

Kernel Version

5.15.146.1-microsoft-standard-WSL2

Distro Version

ubuntu 20.04

Other Software

Docker desktop was uninstalled from the windows system.

Repro Steps

Information

My laptop's IP is 192.168.0.102 in WLAN.

Is was worked for me before. But after I reset my system, I can not make it work again.

  1. Start a clash app with port 7890
  2. Go into the wsl environment
  3. Execute command telnet 127.0.0.1 7890
  4. Not connected

First

.wslconfig

[wsl2]
networkingMode=mirrored

commands and result

detail
msojocs@DESKTOP-1TV4OAG:~$ ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
    link/ether 00:50:56:c0:00:08 brd ff:ff:ff:ff:ff:ff
    inet6 fe80::9c5b:a645:98b4:bfc2/64 scope link noprefixroute
       valid_lft forever preferred_lft forever
3: eth1: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc mq state DOWN group default qlen 1000
    link/ether da:80:83:b3:d6:cb brd ff:ff:ff:ff:ff:ff
4: eth2: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
    link/ether 00:50:56:c0:00:01 brd ff:ff:ff:ff:ff:ff
    inet6 fe80::de9f:1113:2891:d898/64 scope link noprefixroute
       valid_lft forever preferred_lft forever
5: loopback0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
    link/ether 00:15:5d:e1:6c:93 brd ff:ff:ff:ff:ff:ff
    inet6 fe80::3b9f:eb69:8d5e:9e71/64 scope link noprefixroute
       valid_lft forever preferred_lft forever
6: eth3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
    link/ether d8:80:83:b3:d6:cb brd ff:ff:ff:ff:ff:ff
    inet 192.168.0.102/24 brd 192.168.0.255 scope global noprefixroute eth3
       valid_lft forever preferred_lft forever
    inet6 fe80::7df1:6f90:3370:4cd1/64 scope link nodad noprefixroute
       valid_lft forever preferred_lft forever
7: eth4: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc mq state DOWN group default qlen 1000
    link/ether fa:80:83:b3:d6:cb brd ff:ff:ff:ff:ff:ff
8: eth5: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc mq state DOWN group default qlen 1000
    link/ether ea:80:83:b3:d6:cb brd ff:ff:ff:ff:ff:ff
msojocs@DESKTOP-1TV4OAG:~$ telnet 127.0.0.1 7890
Trying 127.0.0.1...
telnet: Unable to connect to remote host: Connection refused
msojocs@DESKTOP-1TV4OAG:~$ telnet 192.168.0.102 7890
Trying 192.168.0.102...
telnet: Unable to connect to remote host: Connection refused
msojocs@DESKTOP-1TV4OAG:~$

Second

.wslconfig

[wsl2]
networkingMode=mirrored
[experimental]
hostAddressLoopback=true

commands and result

detail
msojocs@DESKTOP-1TV4OAG:~$ ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
    link/ether 00:50:56:c0:00:08 brd ff:ff:ff:ff:ff:ff
    inet6 fe80::9c5b:a645:98b4:bfc2/64 scope link noprefixroute
       valid_lft forever preferred_lft forever
3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
    link/ether da:80:83:b3:d6:cb brd ff:ff:ff:ff:ff:ff
    inet6 fe80::bf84:bc17:2e88:c5c0/64 scope link noprefixroute
       valid_lft forever preferred_lft forever
4: eth2: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
    link/ether 00:50:56:c0:00:01 brd ff:ff:ff:ff:ff:ff
    inet6 fe80::de9f:1113:2891:d898/64 scope link noprefixroute
       valid_lft forever preferred_lft forever
5: loopback0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
    link/ether 00:15:5d:e1:6c:93 brd ff:ff:ff:ff:ff:ff
    inet6 fe80::3b9f:eb69:8d5e:9e71/64 scope link noprefixroute
       valid_lft forever preferred_lft forever
6: eth3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
    link/ether d8:80:83:b3:d6:cb brd ff:ff:ff:ff:ff:ff
    inet 192.168.0.102/24 brd 192.168.0.255 scope global noprefixroute eth3
       valid_lft forever preferred_lft forever
    inet6 fe80::7df1:6f90:3370:4cd1/64 scope link nodad noprefixroute
       valid_lft forever preferred_lft forever
7: eth4: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc mq state DOWN group default qlen 1000
    link/ether fa:80:83:b3:d6:cb brd ff:ff:ff:ff:ff:ff
8: eth5: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc mq state DOWN group default qlen 1000
    link/ether ea:80:83:b3:d6:cb brd ff:ff:ff:ff:ff:ff
msojocs@DESKTOP-1TV4OAG:~$ telnet 127.0.0.1 7890
Trying 127.0.0.1...
telnet: Unable to connect to remote host: Connection refused
msojocs@DESKTOP-1TV4OAG:~$ telnet 192.168.0.102 7890
Trying 192.168.0.102...
Connected to 192.168.0.102.
Escape character is '^]'.

Expected Behavior

The command telnet 127.0.0.1 7890 can success.

Actual Behavior

The command telnet 127.0.0.1 7890 is failed.

Diagnostic Logs

Log

Collected log

Steps:

  1. execute wsl --shutdown
  2. execute .\collect-networking-logs.ps1
  3. execute wsl
  4. execute curl 127.0.0.1:7890
  5. execute telnet 127.0.0.1 7890
  6. execute telnet 192.168.0.102 7890

WslNetworkingLogs-2024-03-16_15-43-33.zip

Other

cat /etc/resolv.conf
# This file was automatically generated by WSL. To stop automatic generation of this file, add the following entry to /etc/wsl.conf:
# [network]
# generateResolvConf = false
nameserver 180.76.76.76
nameserver 223.6.6.6
Copy link

Hi I'm an AI powered bot that finds similar issues based off the issue title.

Please view the issues below to see if they solve your problem, and if the issue describes your problem please consider closing this one and thumbs upping the other issue to help us prioritize it. Thank you!

Open similar issues:

Closed similar issues:

Note: You can give me feedback by thumbs upping or thumbs downing this comment.

@msojocs
Copy link
Author

msojocs commented Mar 16, 2024

Afte view this issue (#10632), I have checked the port binding in wsl:

Can wsl use the port same with windows?

  1. execute python -m http.server --bind 0.0.0.0 with windows, success
  2. execute python3 -m http.server --bind 0.0.0.0 with wsl, failed.

image

Can windows access web started by wsl?

When I use edge in windows, I can access the web by 192.168.0.102, but 127.0.0.1 is not worked.

image

image

@pmartincic
Copy link
Collaborator

What do you get from netstat -an | findstr /c:"7890" | findstr /c:"LISTENING"?

@msojocs
Copy link
Author

msojocs commented Mar 20, 2024

What do you get from netstat -an | findstr /c:"7890" | findstr /c:"LISTENING"?

This is the result.

image

@pffang
Copy link

pffang commented Mar 20, 2024

Similar issue.
If I kill all WSL processes and restart it, I can access Windows localhost:port again.
But if I leave it running for hours, I cannot access Windows localhost:port from WSL.

@msojocs
Copy link
Author

msojocs commented Mar 20, 2024

Similar issue. If I kill all WSL processes and restart it, I can access Windows localhost:port again. But if I leave it running for hours, I cannot access Windows localhost:port from WSL.

This method does not work for me.

@leorg99 leorg99 mentioned this issue Mar 21, 2024
2 tasks
@GitUser200607
Copy link

GitUser200607 commented Mar 25, 2024

Similar issue.
If I kill all WSL processes and restart it, I can access Windows localhost:port again.
But if I leave it running for hours, I cannot access Windows localhost:port from WSL.

Did not work for me too.

@keith-horton
Copy link
Member

If you want to connect to the host from the WSL container by the IP address assigned you'll need to connect to 127.0.01. If you want to connect to the assigned address, you need to set [experimental] hostAddressLoopback=true (see https://learn.microsoft.com/en-us/windows/wsl/wsl-config#experimental-configuration-settings).

But in the original repro, it was sent to 127.0.0.1, so that's valid.
We see a RST immediately returned.

15:44:12.145100 IP 127.0.0.1.60816 > 127.0.0.1.7890: Flags [S], seq 2455237139, win 65495, options [mss 65495,sackOK,TS val 260823200 ecr 0,nop,wscale 7], length 0
15:44:12.145107 IP 127.0.0.1.7890 > 127.0.0.1.60816: Flags [R.], seq 0, ack 2455237140, win 0, length 0

Everything else looks setup correctly (Hyper-V Firewall is setup correctly).
This suggests one of 2 things that I can see:

  1. the app wasn't bound & listening to that port at the time
  2. Cisco's VMWare solution has filters that are causing issues
    (I only bring up VMWare as we have observed many interop issues in the past).

@msojocs
Copy link
Author

msojocs commented Mar 28, 2024

If you want to connect to the host from the WSL container by the IP address assigned you'll need to connect to 127.0.01. If you want to connect to the assigned address, you need to set [experimental] hostAddressLoopback=true (see https://learn.microsoft.com/en-us/windows/wsl/wsl-config#experimental-configuration-settings).

But in the original repro, it was sent to 127.0.0.1, so that's valid. We see a RST immediately returned.

15:44:12.145100 IP 127.0.0.1.60816 > 127.0.0.1.7890: Flags [S], seq 2455237139, win 65495, options [mss 65495,sackOK,TS val 260823200 ecr 0,nop,wscale 7], length 0 15:44:12.145107 IP 127.0.0.1.7890 > 127.0.0.1.60816: Flags [R.], seq 0, ack 2455237140, win 0, length 0

Everything else looks setup correctly (Hyper-V Firewall is setup correctly). This suggests one of 2 things that I can see:

  1. the app wasn't bound & listening to that port at the time
  2. Cisco's VMWare solution has filters that are causing issues
    (I only bring up VMWare as we have observed many interop issues in the past).

I have uninstalled the VMWare just now and reboot the computer, but it still not work.

I think the app was bound the port at the time, because I can not access google without this proxy (google was blocked in my country).

And now I can access google(port is work in host), but telnet 127.0.0.1 7890 still can not work with wsl.

@pffang
Copy link

pffang commented Mar 28, 2024

If you want to connect to the host from the WSL container by the IP address assigned you'll need to connect to 127.0.01. If you want to connect to the assigned address, you need to set [experimental] hostAddressLoopback=true (see https://learn.microsoft.com/en-us/windows/wsl/wsl-config#experimental-configuration-settings).

But in the original repro, it was sent to 127.0.0.1, so that's valid. We see a RST immediately returned.

15:44:12.145100 IP 127.0.0.1.60816 > 127.0.0.1.7890: Flags [S], seq 2455237139, win 65495, options [mss 65495,sackOK,TS val 260823200 ecr 0,nop,wscale 7], length 0 15:44:12.145107 IP 127.0.0.1.7890 > 127.0.0.1.60816: Flags [R.], seq 0, ack 2455237140, win 0, length 0

Everything else looks setup correctly (Hyper-V Firewall is setup correctly). This suggests one of 2 things that I can see:

1. the app wasn't bound & listening to that port at the time

2. Cisco's VMWare solution has filters that are causing issues
   (I only bring up VMWare as we have observed many interop issues in the past).

But I used mirrored mode and no VMWare.

@GitUser200607
Copy link

GitUser200607 commented Mar 28, 2024

I did not changed anything and a couple of weeks ago all worked well.

@wangyw6716
Copy link

Try executing the command

sudo systemctl disable network-manager.service

followed by running wsl.exe --shutdown in PowerShell, and then restart WSL again.

@msojocs
Copy link
Author

msojocs commented Apr 1, 2024

Try executing the command

sudo systemctl disable network-manager.service

followed by running wsl.exe --shutdown in PowerShell, and then restart WSL again.

Ohhh!!!

It is working now. Thank you very much.

image

@wangyw6716
Copy link

Try executing the command

sudo systemctl disable network-manager.service

followed by running wsl.exe --shutdown in PowerShell, and then restart WSL again.

Ohhh!!!

It is working now. Thank you very much.

image

I tried disabling every service until I reached network-manager.service, and finally, the mirrored functionality started working properly. It took me a significant amount of time to figure this out.

@msojocs
Copy link
Author

msojocs commented Apr 1, 2024

solved.

Answer:

#11312 (comment)

@msojocs msojocs closed this as completed Apr 1, 2024
@yunus-sun
Copy link

Try executing the command

sudo systemctl disable network-manager.service

followed by running wsl.exe --shutdown in PowerShell, and then restart WSL again.

Similar issue. It works for me. Thanks so much!

@qgyhd1234
Copy link

Try executing the command

sudo systemctl disable network-manager.service

followed by running wsl.exe --shutdown in PowerShell, and then restart WSL again.

Solved my problem, thanks

@Kutius
Copy link

Kutius commented May 14, 2024

Try executing the command

sudo systemctl disable network-manager.service

followed by running wsl.exe --shutdown in PowerShell, and then restart WSL again.

Failed to disable unit: Unit file network-manager.service does not exist.😢

@gsxgoldenlegendary
Copy link

Try executing the command

sudo systemctl disable network-manager.service

followed by running wsl.exe --shutdown in PowerShell, and then restart WSL again.

Failed to disable unit: Unit file network-manager.service does not exist.😢

The NetworkManager service has been named NetworkManager. You can see https://askubuntu.com/questions/1371275/where-has-the-network-manager-service-in-21-10-gone for details.

@Kutius
Copy link

Kutius commented May 27, 2024

Try executing the command

sudo systemctl disable network-manager.service

followed by running wsl.exe --shutdown in PowerShell, and then restart WSL again.

Failed to disable unit: Unit file network-manager.service does not exist.😢

The NetworkManager service has been named NetworkManager. You can see https://askubuntu.com/questions/1371275/where-has-the-network-manager-service-in-21-10-gone for details.

Unlucky😢😢, it also show: Failed to disable unit: Unit file NetworkManager.service does not exist.

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