XCP-NG Network Interface Renaming Script
After writing the previous post about renaming interfaces in XCP-NG I ran through ChatGPT to create a BASH script to handle this in a more automated fashion. Some testing was done on a virtual machine and all appears to function as intended, but do your own testing. Worst case scenario running an "emergency network reset" through xsconsole will resolve any issues.
The file is available for download:
Or can be downloaded directly to your host using:
wget https://www.themaw.tech/content/files/2025/02/rename-interfaces.sh
Video Guide
Text Guide
Download the file onto your XCP-NG host or paste the content into ~/rename-interfaces.sh
Enable execution with chmod +x ~/rename-interfaces.sh
Run the script with ~/rename-interfaces.sh
The output will look like
=== Pre-Reboot Phase: Renaming Interfaces ===
Current interface mapping:
Name MAC PCI ethN Phys SMBios Driver Version Firmware
eth0 50:6b:8d:97:e6:5f 0000:00:03.0[0] eth0 virtio_net 1.0.0
eth1 50:6b:8d:fc:56:68 0000:00:04.0[0] eth1 virtio_net 1.0.0
eth2 50:6b:8d:d2:ee:99 0000:00:05.0[0] eth2 virtio_net 1.0.0
eth3 50:6b:8d:f5:f7:23 0000:00:06.0[0] eth3 virtio_net 1.0.0
You will be prompted for a destination interface name
Enter destination interface (e.g., eth4):
Then you will be prompted for a source interface name
Enter source interface (e.g., eth8):
A confirmation will appear
Proposed change:
Interface eth2 will be updated with MAC: 50:6b:8d:f5:f7:23
Interface eth3 will be updated with MAC: 50:6b:8d:d2:ee:99
Confirm these changes? (y/n):
Pressing Y then enter will bring down the interfaces and forget the PIFs on the host the script is run on.
Bringing down interfaces eth2 and eth3...
Running interface-rename update...
INFO [2025-02-22 11:28:48] Performing manual update of rules. Not actually renaming interfaces
INFO [2025-02-22 11:28:48] All done
Forgetting old PIF entries...
Once complete you will be prompted to make any additional changes
Do you want to rename another pair of interfaces? (y/n):
If you want to change another set press Y then enter and it will re-list the interfaces. Keep in mind your pending change is not reflected here.
Pressing N then enter will prompt you for a reboot
Saving state for post-reboot reintroduction...
Pre-reboot renaming complete. Please reboot the host to apply changes.
Reboot the host when safe to do so reboot now
.
Once the host is back up run the script again with ~/rename-interfaces.sh
It will check to make sure that XAPI is up and usable before proceeding the bringing the interfaces up and introducting them back to the host.
State file detected. Resuming post reboot phase...
=== Post-Reboot Phase: Reintroducing Interfaces ===
Using local host UUID: 1f4afbe4-a5d1-41c9-b959-78a2da613fa7
Bringing up interface eth1...
Bringing up interface eth3...
Bringing up interface eth2...
Bringing up interface eth4...
Introducing interface eth1 with MAC 50:6b:8d:f5:f7:23 to host 1f4afbe4-a5d1-41c9-b959-78a2da613fa7...
22c06de5-4451-46ee-ccf7-bb963ebcc324
Introducing interface eth3 with MAC 50:6b:8d:fc:56:68 to host 1f4afbe4-a5d1-41c9-b959-78a2da613fa7...
4574fc8b-668e-c629-558d-ae9e819582be
Introducing interface eth2 with MAC 50:6b:8d:b8:3f:b1 to host 1f4afbe4-a5d1-41c9-b959-78a2da613fa7...
1a1c2570-9087-1534-a86c-89583ce5b08c
Introducing interface eth4 with MAC 50:6b:8d:d2:ee:99 to host 1f4afbe4-a5d1-41c9-b959-78a2da613fa7...
d9ec2bbc-212e-2907-744d-0b7973a60b65
Interface reintroduction complete. Your NIC renaming process is finished.
Running interface-rename --list
will reflect the new changes
[12:43 xcpng01 ~]# interface-rename --list
Name MAC PCI ethN Phys SMBios Driver Version Firmware
eth0 50:6b:8d:97:e6:5f 0000:00:03.0[0] eth0 virtio_net 1.0.0
eth1 50:6b:8d:f5:f7:23 0000:00:06.0[0] eth3 virtio_net 1.0.0
eth2 50:6b:8d:b8:3f:b1 0000:00:0b.0[0] eth4 virtio_net 1.0.0
eth3 50:6b:8d:fc:56:68 0000:00:04.0[0] eth1 virtio_net 1.0.0
eth4 50:6b:8d:d2:ee:99 0000:00:05.0[0] eth2 virtio_net 1.0.0