Netplan and How To Get eth0 Back!

Once upon a time eth0 was eth0 on Linux. But then, some people thought it would be a good idea to rename the network interface on boot to correspond and map the name to the physical interface. In many cases, that is a good idea, but for virtual machines that suddenly and miraculously change the physical interface when the bare metal server config is changed, this approach is a bit of a pain. Recently, however, I noticed that if the network is configured via netplan you can get eth0 back!

To get it back, just declare it as follows in your netplan yaml file:

network:
  version: 2
  ethernets:
    eth0:
      match:
        macaddress: 52:51:00:be:ef:01
      set-name: eth0
      dhcp4: no
      addresses:
        - 192.168.42.242/24
      routes:
        - to: default
          via: 192.168.42.1
      nameservers:
        addresses: [8.8.8.8,8.8.4.4]

This links the MAC address of the network interface to eth0. No more looking through log files when the network interface is not configured when a VM is moved. As long as the MAC address that can be set for the VM in the hypervisor remains the same, eth0 will come up. And if the MAC address changes, the hypervisor will tell you the new MAC address and changing the netplan yaml file is straight forward!

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.