On Linux you can easily change the MAC address of your NIC. The same is true even if Linux is installed directly on a bare metal machine. Even if the physical MAC address does not change, the MAC address can be overwritten as a logical part recognized as the OS.
On the other hand, in modern OpenStack and K8s, there are many scenes where virtual NICs are automatically created. In such a scene, I would like to write about the method when you want to change the MAC address of the virtual NIC.
Of course, once the virtual NIC is created, it is easy to change it manually. However, in the case of a scene where communication starts instantly after creation, that may not be in time. It's troublesome above all. So I want to do it automatically. I'll leave an article about how to do that, though it's easy.
To be honest, I don't think there is such a situation, but I hope it helps someone.
And if there is a better way, please let me know!
Have udev change it automatically. Seriously udev is too convenient.
Create the following rule file and put it under /etc/udev/rules.d/. Just place it and it will work automatically.
KERNEL
.*
here.RUN
. Now hit the ip command to change the MAC address.$ name
. By using it in combination with RUN, you can aim at a specific NIC.[macaddress]
, specify the MAC address you want to change.ACTION=="add", SUBSYSTEM=="net", KERNEL=="[nic_name]", RUN+="ip link set dev $name address [macaddress]"
The above can be written in multiple lines in a single rule file. I think it is more convenient to write the MAC address change system in one file.
/etc/udev/rules.d/75-mac-spoof.rules
ACTION=="add", SUBSYSTEM=="net", KERNEL=="vlan1000", RUN+="ip link set dev $name address 0a:1b:2c:3d:4e:5f"
ACTION=="add", SUBSYSTEM=="net", KERNEL=="vlan2000", RUN+="ip link set dev $name address 00:11:22:33:44:55"
ACTION=="add", SUBSYSTEM=="net", KERNEL=="vlan3000", RUN+="ip link set dev $name address aa:bb:cc:dd:ee:ff"
Recommended Posts