-3

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?

0

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.

set-name: <(scalar)>

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).

For example:

$ 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
  • On boot, how will the instance have the mac_address information available? I am talking about the case when we want to spin instances from a VM image on a hypervisor. The NIC MAC address information will not be able to be hard coded. – user304255 Aug 27 '18 at 18:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.