I have two network interfaces- eth0 and eth1 on the Ubuntu image I am building. I want to create cloud instances from that image. For every cloud instance it creates, every instance will have those two network interfaces. However, the requirement is that, the interfaces are renamed to, say, interface0 and interface1 respectively. How can I configure that using cloud-init on instance boot up?
The docs for cloud-init show the following examples in this section - Networking Config Version 2:
# all cards on second PCI bus match: name: enp2* # fixed MAC address match: macaddress: 11:22:33:AA:BB:FF # first card of driver ``ixgbe`` match: driver: ixgbe name: en*s0
So long as the match is specific to a single device, you can use the
set-name: to define whatever name you want for the interface.
When matching on unique properties such as path or MAC, or with additional assumptions such as “there will only ever be one wifi device”, match rules can be written so that they only match one device. Then this property can be used to give that device a more specific/desirable/nicer name than the default from udev’s ifnames. Any additional device that satisfies the match rules will then fail to get renamed and keep the original kernel name (and dmesg will show an error).
$ cat /etc/cloud/cloud.cfg.d/custom-networking.cfg network: version: 2 ethernets: interface0: match: mac_address: "52:54:00:12:34:00" set-name: interface0 addresses: - 192.168.1.10/255.255.255.0 gateway4: 192.168.1.254