WSL: WSL 2 - Static MAC Address or Changing MAC After Booting Without Breaking Internet Connection

Environment

Windows build number: 10.0.19041.264
Your Distribution version: Ubuntu 20.04
Whether the issue is on WSL 2 and/or WSL 1: WSL 2

Steps to reproduce

sudo ip link set dev eth0 down
sudo ip link set dev eth0 address 00:15:5d:09:b0:a0 # or any address, which will be fixed
sudo ip link set dev eth0 up

Expected behavior

IPv4 and IPv6 address can change(and would change), but the connection to the local physical machine and internet should be OK.

Actual behavior

I cannot use any program that requires to connect to the internet and GUI program which is attached to the local physical machine’s vcxsrv X server.

About this issue

  • Original URL
  • State: open
  • Created 6 years ago
  • Reactions: 11
  • Comments: 40

Most upvoted comments

I have another vendor that relies on the MAC for licensing and just got bit by this. As a result, this issue has just made WSL2 useless for our needs. I hope this issues is getting some attention and a patch is forthcoming?

Also, if it’s possible to modify this issue’s title, can it be changed to something like “WSL 2 - MAC address changes every time network interface is started”?

For software that only checks eth0, I’m using a workaround involving changing the bond0 interface name to eth0. For example, something like this in .bashrc:

mac=7b:6c:2a:30:2b:08
gateway=$(ip route | awk '/default via /{print $3; exit}' 2>/dev/null)
if ! ip link show | grep -q $mac; then
    sudo ip link set dev eth0 down
    sudo ip link set dev eth0 name eth1
    sudo ip link set dev eth1 up
    sudo ip route add default via $gateway dev eth1
    sudo ip link set dev bond0 down
    sudo ip link set dev bond0 address $mac
    sudo ip link set dev bond0 name eth0
    sudo ip link set dev eth0 up
fi

The old eth0 is renamed to eth1 but all connections still appear to work after the rename.

Thanks @darchons this works perfect. To change my MAC address automatically on WSL startup:

I put your snippet in a bash file “wsl.mac” that I put in /etc/ and that I made executable.

Then I created wsl.conf in /etc/ with the following content:

[boot]
command = sudo /etc/wsl.mac

For software that only checks eth0, I’m using a workaround involving changing the bond0 interface name to eth0. For example, something like this in .bashrc:

mac=7b:6c:2a:30:2b:08
gateway=$(ip route | awk '/default via /{print $3; exit}' 2>/dev/null)
if ! ip link show | grep -q $mac; then
    sudo ip link set dev eth0 down
    sudo ip link set dev eth0 name eth1
    sudo ip link set dev eth1 up
    sudo ip route add default via $gateway dev eth1
    sudo ip link set dev bond0 down
    sudo ip link set dev bond0 address $mac
    sudo ip link set dev bond0 name eth0
    sudo ip link set dev eth0 up
fi

The old eth0 is renamed to eth1 but all connections still appear to work after the rename.

I want to add my solution to the already presented bulk as well. Since my original comments (https://github.com/microsoft/WSL/issues/5352#issuecomment-678108088) four years ago, a few things changed but this problem still persists. I have since switched machines and reinstalled WSL and MATLAB a few times. Currently, the WSL only has two network devices by default:

ip address
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
    ...
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1492 qdisc mq state UP group default qlen 1000
    link/ether SOME:MAC:ADDRESS brd ff:ff:ff:ff:ff:ff
    ...

When MATLAB is registered in this situation, the license will include the mac address of eth0. After restarting the machine, the mac address of eth0 changes and MATLAB will complain since it cannot find any device whose mac address matches the one in the license. Therefore, I simply create an additional network device with the mac address in the license with this command:

sudo ip link add bond0 address SOME:MAC:ADDRESS type bond

Afterwards, MATLAB can be started without license errors. Unfortunately, this device is lost when the machine is shut down. Therefore, instead of executing the command above after every restart, one can let this command automatically be executed every time WSL is started by adding this to the file /etc/wsl.conf within the WSL:

[boot]
command = ip link add bond0 address 00:15:5d:e1:cf:3f type bond

I think I am getting the same issue with Gurobi in WSL2, the licence does not work after reboot due to HostID mismatch. Gurobi-recommended solution is to switch to WSL1.

I have the same issue. I am trying to run MATLAB in WSL2 and get a license error every time I restart the WSL because the mac addresses change.

Hey fritut08, I solved the license problem derived from the non-supported static mac address. Below the guy “therealkenc” mentioned, you can use the “bond0” field to attach the license when issuing licenses.

Hey mauver15, it does not work for me since MATLAB seems to use the mac address of eth0 when issuing the license but uses a combination of eth0 and bond0 when checking the license. So, whenever I start MATLAB after a restart of WSL2 it tries to compare the eth0 from when the license was issued with the current “eth0 bond0”.

grafik

Ok, I got it.

  1. Set the static mac address of the “bond0” field. Do change mac address to the address you are previously applied at the license. And this change does not affect your internet connection. (In your uploaded picture, there are two mac addresses that the license looks for. One is from eth0/other one is bond0) -> sudo ip link set dev bond0 address XX:XX:XX:XX:XX:XX

  2. Confirm that is your bond0’s mac address fixed.

  3. Re-activate your license.

You can do this with the flows I wrote.

Ok, I got it.

1. Set the static mac address of the "bond0" field. Do change mac address to the address you are previously applied at the license.
   And this change does not affect your internet connection.
   (In your uploaded picture, there are two mac addresses that the license looks for. One is from eth0/other one is bond0)
   -> sudo ip link set dev bond0 address XX:XX:XX:XX:XX:XX

2. Confirm that is your bond0's mac address fixed.

3. Re-activate your license.

You can do this with the flows I wrote.

No, I do not think the bond0 address is the problem. The bond0 address is not used in the license files after all. It is the eth0 address that is mentioned in the license file. So I would have to change that.

I had the same issue with Matlab but was actually able to resolve it by setting a static bond0 address as per @therealkenc’s suggestion in #5866. The installer was indeed echoing both bond0 and eth0 addresses, and the license file was looking for the eth0 one, initially. But I got a new license that is tied to the bond0 address and so far it seems to work fine (after a few reboots).

Here are the steps that worked for me:

  1. Log into the MathWorks license center
  2. Select license
  3. Go to “install and activate” tab
  4. Go to “activate to retrieve license file” (under “related tasks”)
  5. Click on the “activate a computer” button
  6. Use the static bond0 address as the host ID
  7. Download the license file and replace the old one

I hope this helps, at least specifically for Matlab.

Many thanks to @minmossi, @mauver15, and @therealkenc for their comments and solution! This was a very annoying issue.

For software that only checks eth0, I’m using a workaround involving changing the bond0 interface name to eth0. For example, something like this in .bashrc:

mac=7b:6c:2a:30:2b:08
gateway=$(ip route | awk '/default via /{print $3; exit}' 2>/dev/null)
if ! ip link show | grep -q $mac; then
    sudo ip link set dev eth0 down
    sudo ip link set dev eth0 name eth1
    sudo ip link set dev eth1 up
    sudo ip route add default via $gateway dev eth1
    sudo ip link set dev bond0 down
    sudo ip link set dev bond0 address $mac
    sudo ip link set dev bond0 name eth0
    sudo ip link set dev eth0 up
fi

The old eth0 is renamed to eth1 but all connections still appear to work after the rename.

When I try this approach, I got the following errors

Cannot find device "bond0"
Cannot find device "bond0"
Cannot find device "bond0"
Cannot find device "eth1"

any idea?

I used the intelFPGA suites and it seems that it checks only eth0 and i can’t change this. So i need to put a fixed MAC ADRESS to eth0 …

I’m also having this issue while trying to use WSL within an organization that has firewall rules locally implemented by Symantec Endpoint Protection. We can apply firewall rule to MAC but if it keeps changing, this will not work. Any ideas?

@Biswa96 Actually, many programs do like Xilinx Vivado, although I think it’s certainly a horrible decision too.

sudo ip route add default via (windows_side_ipconfig_vEthernet_ip) dev eth0 doesn’t help.

Was able to repro here.