Skip to content

Networking mirrored can't work on WSL2 #10632

Closed

Description

@yqs112358

Windows Version

Microsoft Windows [Version 10.0.22631.2500]

WSL Version

2.0.14.0

Are you using WSL 1 or WSL 2?

  • WSL 2
  • WSL 1

Kernel Version

5.15.133.1-1

Distro Version

Ubuntu 20.04

Other Software

None

Repro Steps

  • Set .wslconfig:
[experimental]
networkingMode=mirrored
dnsTunneling=true
firewall=true
  • wsl --shutdown to stop WSL
  • Allow tcp port 8000 in Windows firewall settings
  • Restart WSL

Expected Behavior

Both WSL and Windows can successfully access 127.0.0.1:8000 by curl

Actual Behavior

My laptop's IP is 192.168.3.11 in WLAN

1. Test HTTP server on port 8000 in WSL

Execute python -m http.server in WSL. Output:
Serving HTTP on 0.0.0.0 port 8000 (http://0.0.0.0:8000/) ...

  • Execute curl in WSL   (WSL curl -> WSL server)
    • curl http://192.168.3.11:8000 succeeded.
    • curl http://localhost:8000 failed. Cannot connect. Reason: Timeout
    • curl http://127.0.0.1:8000 failed. Cannot connect. Reason: Timeout
  • Execute curl in Windows   (Windows curl -> WSL server)
    • curl http://192.168.3.11:8000 failed. Cannot connect. Reason: Timeout
    • curl http://localhost:8000 failed. Cannot connect. Reason: Timeout
    • curl http://127.0.0.1:8000 failed. Cannot connect. Reason: Timeout

2. Test HTTP server on port 8000 in Windows

Execute python -m http.server --bind 0.0.0.0 in Windows. Output:
Serving HTTP on 0.0.0.0 port 8000 (http://0.0.0.0:8000/) ...

  • Execute curl in WSL   (WSL curl -> Windows server)
    • curl http://192.168.3.11:8000 failed. Cannot connect. Reason: Connection refused
    • curl http://localhost:8000 failed. Cannot connect. Reason: Timeout
    • curl http://127.0.0.1:8000 failed. Cannot connect. Reason: Timeout
  • Execute curl in Windows   (Windows curl -> Windows server)
    • curl http://192.168.3.11:8000 succeeded.
    • curl http://localhost:8000 succeeded.
    • curl http://127.0.0.1:8000 succeeded.

Diagnostic Logs

/etc/resolv.conf

nameserver 127.0.0.42

ifconfig in WSL

br-d0766515769e: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
        inet 172.18.0.1  netmask 255.255.0.0  broadcast 172.18.255.255
        ether 02:42:03:7d:ec:8b  txqueuelen 0  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

docker0: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
        inet 172.17.0.1  netmask 255.255.0.0  broadcast 172.17.255.255
        ether 02:42:98:0b:74:7d  txqueuelen 0  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

eth1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.3.11  netmask 255.255.255.0  broadcast 192.168.3.255
        inet6 fe80::1c95:c4bd:2c0b:12fd  prefixlen 64  scopeid 0x20<link>
        ether 40:ec:99:cf:f2:a6  txqueuelen 1000  (Ethernet)
        RX packets 280  bytes 21218 (21.2 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 158  bytes 21856 (21.8 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 86  bytes 10468 (10.4 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 86  bytes 10468 (10.4 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

loopback0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        ether 00:15:5d:d8:86:a8  txqueuelen 1000  (Ethernet)
        RX packets 20  bytes 1416 (1.4 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 12  bytes 888 (888.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

Activity

  1. changed the title [-]Networking mirrored can't work on WSL 2.0.4.0[/-] [+]Networking mirrored can't work on 127.0.0.1[/+] on Oct 14, 2023
  2. changed the title [-]Networking mirrored can't work on 127.0.0.1[/-] [+]Networking mirrored can't work on 127.0.0.1, only localhost[/+] on Oct 14, 2023
  3. changed the title [-]Networking mirrored can't work on 127.0.0.1, only localhost[/-] [+]Networking mirrored can't work on WSL 2.0.4.0[/+] on Oct 15, 2023
  4. keith-horton commented on Oct 18, 2023

    @keith-horton
    Member

    Hi there.
    Are you setting up the server within the Docker container in Linux? Note that Docker has its own IP address on its own network device. How did you configure it in Linux to forward requests to that address within Docker?

    If you setup a listener within Docker within Linux, you'll want to let WSL know that the port is reserved and used by the WSL container by adding this to the .wslconfig file under experimental:

    ignoredPorts=8000

  5. yqs112358 commented on Oct 19, 2023

    @yqs112358
    Author

    Thanks for your remind😂
    But this test is actually done in real WSL, not in a docker container.
    I have removed docker-related content in this issue to avoid confusion.

  6. sf467 commented on Oct 19, 2023

    @sf467

    The mirrored network feature of wsl doesn't work on my machine either.
    my win11 is dev channal, build 23570, but......
    image
    image

  7. FlowerBirds commented on Oct 20, 2023

    @FlowerBirds

    Only one lo network card:
    image

    update wsl 1.x to 2.0.4 and window to 23H2.

    what's wrong with me ?

  8. keith-horton commented on Oct 23, 2023

    @keith-horton
    Member
  9. shigenobuokamoto commented on Oct 24, 2023

    @shigenobuokamoto

    YQ (@yqs112358)
    can you try this?

    curl --noproxy \* http://127.0.0.1:8000
    
  10. keith-horton commented on Oct 24, 2023

    @keith-horton
    Member

    Keith Horton (@keith-horton) https://github.com/FlowerBirds/wsl2/blob/main/WslLogs-2023-10-24_08-49-22.zip

    Thanks

    Thank you. I tried 4 different tools to open the trace, but all were able to only resolve a couple of lines of a trace. Sorry. Could we try again and see if we get a more usable trace?

    We have a new script to collect networking logs, could you run this? https://github.com/microsoft/WSL/blob/master/diagnostics/collect-networking-logs.ps1

    Thanks!

  11. yqs112358 commented on Oct 25, 2023

    @yqs112358
    Author

    YQ (@yqs112358) can you try this?

    curl --noproxy \* http://127.0.0.1:8000
    

    Sorry, but the same: cannot connect. (Both in Windows and WSL)
    I think it's not the problem of proxy because I have not set $http_proxy

  12. yqs112358 commented on Oct 25, 2023

    @yqs112358
    Author

    I have upgraded to WSL preview 2.0.6 and tried again, but the problem still exists.
    Actual Behavior section is updated. I have tested creating server in Windows too and posted the result above.

  13. 17 remaining items

  14. keith-horton commented on Mar 26, 2024

    @keith-horton
    Member

    YQ (@yqs112358) , you can connect to WSL from the host with mirrored mode, but you need allow loopback traffic through Hyper-V Firewall, and you need to create a Hyper-V Firewall rule to allow the port you want into the WSL container.

    See https://learn.microsoft.com/en-us/windows/security/operating-system-security/network-security/windows-firewall/hyper-v-firewall - look for LoopbackEnabled and New-NetFirewallHyperVRule.

  15. yunsii commented on Mar 28, 2024

    @yunsii

    #11172 May be the same problem

  16. wade6716 commented on Apr 1, 2024

    @wade6716

    Try executing the command

    sudo systemctl disable network-manager.service
    

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

  17. keith-horton commented on Apr 1, 2024

    @keith-horton
    Member

    Yes. SystemD running its own Network Manager service is highly likely to hit compatibility issues with WSL.

  18. yunsii commented on Apr 2, 2024

    @yunsii

    @wangyw6716 Cool, it works like a charm.

  19. keith-horton commented on Apr 2, 2024

    @keith-horton
    Member

    YQ (@yqs112358) , can you see if you have NetworkManager running? that's not going to work well with WSL.

  20. yunsii commented on Apr 2, 2024

    @yunsii

    Keith Horton (@keith-horton) Before I disable network-manager.service, I checked status by systemctl status network-manager.service, and network-manager.service is running. It works after I disabled network-manager.service.

  21. keith-horton commented on Apr 2, 2024

    @keith-horton
    Member

    Thanks!

  22. yqs112358 commented on Apr 3, 2024

    @yqs112358
    Author

    Solved:
    I have uninstall WSL and Ubuntu thoroughly, and then re-install again.
    After a complete reinstall, networkingMode=mirrored works well. Both directions are accessiable by curl 127.0.0.1 or localhost.
    In new Ubuntu, I have found that network-manager.service does not exist. Maybe this service does have some what of effect, or maybe there was some problem with the network configuration of my old WSL. Anyway, this feature is now fully functional. Thanks for your hard work 😊 Keith Horton (@keith-horton) @wangyw6716

    Env:

    WSL Version: 2.2.1.0
    Core Version: 5.15.150.1-2
    WSLg Version: 1.0.60
    MSRDC Version: 1.2.5105
    Direct3D Version: 1.611.1-81528511
    DXCore Version: 10.0.25131.1002-220531-1700.rs-onecore-base2-hyp
    Windows Version: 10.0.22631.3374
    
  23. yqs112358 commented on Apr 3, 2024

    @yqs112358
    Author

    By the way, does Docker currently support network=mirrored well?
    Some of my work dependents on this and it would be great if mirrored could be supported effectively.

  24. keith-horton commented on Apr 3, 2024

    @keith-horton
    Member

    We have been working closely with Docker - they have made positive changes for new WSL features such as mirrored mode and DNS tunneling :)

    I would recommend using their latest updates.

  25. RomanZhakhovTR commented on Jun 21, 2024

    @RomanZhakhovTR

    Disabling network-manager.service helped,
    Thanks a lot :)

  26. jahanarun commented on Sep 7, 2024

    @jahanarun

    YQ (@yqs112358) can you try this?

    curl --noproxy \* http://127.0.0.1:8000
    

    This works!
    Now, how do I use this noproxy mode in other apps?

  27. FrankFang commented on Nov 11, 2024

    @FrankFang

    Roman Zhakhov (@RomanZhakhovTR) How could I disable network-manager.service, I could not find it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions