microsoft / WSL

Issues found on WSL
https://docs.microsoft.com/windows/wsl
MIT License
17.34k stars 814 forks source link

MacAddressSpoofing not working for WSL2 bridged adapter #8602

Closed xJason6 closed 8 months ago

xJason6 commented 2 years ago

Version

Microsoft Windows [Version 10.0.19042.1766]

WSL Version

Kernel Version

5.10.16

Distro Version

Ubuntu-20.04

Other Software

Hyper-V Manager 10.0.19041.1

Repro Steps

  1. Stop WSL:
    wsl --shutdown
  2. Change connection type via Hyper-V Manager -> Virtual Switch Manager -> WSL Set type to "External" and choose ethernet adapter with static ip address set (e.g. 192.168.1.2)
  3. Enable MacAddressSpoofing on WSL Network Adapter:
    Set-VMNetworkAdapter -ManagementOS -Name WSL -MacAddressSpoofing On
  4. Run WSL and set static IP address on eth0 adapter in Ubuntu, e.g.:
    sudo ip addr add 192.168.1.3 dev eth0
  5. Ping Windows host:
    ping 192.168.1.2

    SUCCESS

  6. Change Ubuntu eth0 MAC address, e.g.:
    sudo ip link set dev eth0 down
    sudo ip link set dev eth0 address 00:15:5d:7a:02:51
    sudo ip link set dev eth0 up
  7. Ping Windows host again:
    ping 192.168.1.2

    FAIL

Expected Behavior

Since MacAddressSpoofing is enabled traffic should not be blocked after MAC change and ping should succeed.

Remarks:

Actual Behavior

Ping fails since all MAC addresses except default one are blocked.

Biswa96 commented 2 years ago

It is possible to change MAC address of the virtual NIC in another way. I do not know if it is possible with Set-VMNetworkAdapter. To change MAC address of WSL2 NIC, I removed the attached network endpoint and create a new one with different MAC address. Then attached it with WSL2 VM. I have shared the code in that thread.

xJason6 commented 2 years ago

This issue is not about changing the MAC - it's about MacAddressSpoofing not working. I already provided some information how I stumbled upon this issue: I cannot set same MAC on both Ubuntu and nested VM. So what I want to achieve is unblocking other MAC addresses than default one - this is what I think MacAddressSpoofing option is for.

tadshi commented 2 years ago

Also run into this problem these days. I'm trying to set up my QEMU, which use a tap interface for its network, on WSL2. Appreantly, the packets from QEMU have a unique source MAC address. I managed to bridge the tap interface and eth0, but when I use wireshark to dump the traffic of eth0(on WSL2) and the traffic of vEthernet interface(on Windows) it just doesn't work. Only packets whose source MAC address is identical to eth0's can be captured on Windows.

I have tried to set MACAddressSpoofing on the adapter but there's no luck. And adding another dummy adapter with tap MAC address to WSL switch in hope of fooling the adapter does not work as well.

So I'm curious about how to pass a packet with arbitary source MAC address from WSL2 to Windows. I keep the WSL switch an internel switch so this problem may not be limited to an externel switch.

By the way, This thread on Superuser give more details but it seems that no solution has been found.

xJason6 commented 2 years ago

The thread on Superuser is mine - I tried to clarify the origin of the problem with nested VM networking and possibly find a workaround but it came out that the real problem is MAC filtering and the fact that the MAC spoofing doesn't work for WSL2 adapter. This is why I reported this issue.

microsoft-github-policy-service[bot] commented 8 months ago

This issue has been automatically closed since it has not had any activity for the past year. If you're still experiencing this issue please re-file this as a new issue or feature request.

Thank you!