How to change the MAC address of an automatically created virtual NIC to be event driven

Overview

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!

Method

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.

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

How to change the MAC address of an automatically created virtual NIC to be event driven
An introduction to object orientation-let's change the internal state of an object
How to run the Export function of GCP Datastore automatically
How to get rid of the "Tags must be an array of hashes." Error in the qiita api
How to display the CPU usage, pod name, and IP address of a pod created with Kubernetes
How to change the log level of Azure SDK for Python
How to know the internal structure of an object in Python
How to change the color of just the button pressed in Tkinter
How to find the memory address of a Pandas dataframe value
I summarized how to change the boot parameters of GRUB and GRUB2
How to easily switch the virtual environment created by Conda on Jupyter
How to play a video while watching the number of frames (Mac)
Script to change the description of fasta
How to check the version of Django
[Python3] Code that can be used when you want to change the extension of an image at once
How to build an environment for using multiple versions of Python on Mac
How to access the contents of a Linux disk on a Mac (but read-only)
How to change the appearance of unselected Foreign Key fields in Django's ModelForm
How to calculate the volatility of a brand
How to find the area of the Voronoi diagram
How to specify the NIC to scan with amazon-dash
[Python] How to change the date format (display format)
Change the decimal point of logging from, to.
Get only the address part of NIC (eth0)
[Blender] How to get the selection order of vertices, edges and faces of an object
How to avoid the cut-off label of the graph created by the plot module using matplotlib
How to limit the API to be published in the C language shared library of Linux
How to change the generated image of GAN to a high quality one to your liking