2023-08-08

Setting up vm ubuntu for cloning (making VM Template)

The Goals : Assign Static or Dynamic IP address regardless the ethernet name.

In some article wrote that should to remove /etc/machine-id but in this case we facing with ubuntu that using netplan, that cofiguring network on boot. so don't delete it, it will make some startup not working and can't assign the ip address, and if you already delete it, you can create again with sudo systemd-machine-id-setup then reboot.

Next we Use mainif: instead of using ethernet name, because of Starting with v197, systemd/udev under Linux automatically assigns predictable, stable network interface names [1]. them we use name: for matching if with the ethernet name using prefix or posfix, cmiiw idk either prefix or postfix, ya basically like that.

we can change the config at /etc/netplan/whatever-config.yaml to seem like code below. note: you need some yaml writing rule to edit the yaml file, but the point is the yaml indentation.

sudo nano /etc/netplan/whatever-config.yaml

network:
  ethernets:
    mainif:
      match:
        name: en*
      dhcp4: true
      dhcp-identifier: mac
  version: 2

Then apply using sudo netplan apply then reboot.

References :

[1] https://www.thomas-krenn.com/en/wiki/Predictable_Network_Interface_Names

https://askubuntu.com/questions/1131191/port-a-working-etc-network-interface-set-into-etc-netplan-name-yml

https://netplan.readthedocs.io/en/latest/netplan-yaml/

Share: