How to preserve MAC address of primary ENI (eth0) on AWS EC2 instances

Mariusz Dworniczak
Nordcloud Engineering
3 min readApr 5, 2022

The other day one of my coworkers wrote on the company Slack:

I have an EC2 instance with an ENI attached (just the default one). I need to migrate to a new EC2 instance (different base image) but need to also make sure, that the MAC address and if possible (but MAC is more important) the IP do not change during the migration. I have been doing some digging but could not find a definitive answer if this was possible or not.
The background is, that license server software is running on this machine which is “locked” through the MAC address and it would cause a lot of effort to switch to a new MAC for all his servers…

Obviously, there wouldn’t be a problem if had attached the secondary network interface and bonded the license with the MAC address of this secondary interface. Then he could detach this network interface from the old EC2 instance and then attach it to the new EC2 instance.

Unfortunately, he assigned the license to the MAC address of eth0, and normally it is not possible to detach the default (primary) network interface from an instance.

Detaching eth0 is not possible

So what to do in a situation where an instance associated with MAC/IP address is terminated but we need to preserve the address beyond the instance lifecycle.

It is possible to try this approach.

Here is a picture from the old instance with the MAC address we would like to preserve:

eth0 properties with MAC address shown

As you see the MAC address is: 12:36:fa:70:67:91

Now we must change the termination behaviour of this ENI card (not the old instance), so the ENI is protected against instance termination.

Please see the picture below:

Change termination behaviour for eth0

By default, this check box is marked so we need to uncheck it.

Now we can terminate the old instance. The OLD_Instance is terminated and its primary interface remains available with clear Attachment status.

the old instance is terminated
but the ENI from the old instance is available to be attached.

So after these operations we have available ENI to be used in the same subnet.

The old parameters including desired MAC 12:36:fa:70:67:91 as you can see are preserved.

During the creation of the new instance, we can select preserved network interface so the new instance will have the same IP address but also MAC address.

Choose the old card during creation of a new machine

I hope you will find this article helpful. Thank you.

--

--