With recent Debian-based systems (e.g. Debian12, Ubuntu20+) detaching and re-attaching network interfaces to VMs can raise issues.
The cause is that the MAC address of the NIC is hard-written in the netplan (/etc/netplan/netplan.yaml) file via cloud-init at instance creation. If the network interface is removed and reattached the system cannot assign the new MAC address, raising the following error on the console log::
... stages.py[WARNING]: Failed to rename devices: [nic not present] Cannot rename mac=fa:16:3e:69:15:67 to ens3, not available.
As a consequence, the VM is no longer reachable
Here is the procedure to correctly detach a VM NIC from Network A and attach to Network B.
- On the OpenStack dashboard, go to Network -> Networks
- Select the private network attached to the VM (Network A) and click on Ports
- Find the port attached to the VM (e.g. looking for the IP address) and copy the correspondent MAC address
- (alternatively: SSH log on the machine; cat file /etc/netplan/<netplan_name>.yaml and copy the MAC address)
- Important: Take note of the SECURITY GROUPS attached to the VM as they will get detached together with the NIC!
- Detach the interface from the VM:
- go to Compute -> Instances; from the drop-down menu of the VM select Detach interface; on the pop-up windows select the IP address of the VM, then click Detach interface
- Go to Network -> Networks, select the network to be attached to the VM (Network B), click on Ports
- Click on Create Port
- On the pop-up window optionally choose a name for the port and PASTE the original MAC address in the MAC Address box
- Go back to the Instance page
- from the drop-down menu of the VM select Attach interface
- From the menu "The way to specify an Interface" select "By Port" and in the Port menu select the port previously created
- From the drop-down menu of the VM select Edit security Groups
- Re-add the security group previously attached to the VM
- Reboot the VM
Now the VM is correctly attached to the new network!
non-default (FAST and CAPACITY) volume types (garr-ct1 and garr-pa1 regions)
non-default (FAST and CAPACITY) volume types (garr-ct1 and garr-pa1 regions)