Categories
Tech

Change network adapter config in Ubuntu and Debian after hardware changes

This post explains updating netplan and /etc/network/interfaces configs

Short version

Ubuntu
sudo nano /etc/netplan/.yaml
change old interface name to new interface name
sudo netplan apply

Debian
nano /etc/network/interfaces
change old interface name to new interface name

The problem

This is mostly a problem on VMs. If you add or change NICs (changing hypervisors, NIC types, etc.) it may not come back up with the same interface name. To give you a better idea of why this happens here’s how I broke it for the example.

The test VM’s ip a output.

I’ll add a second NIC to get a new interface name and remove the old NIC. This simulates changing the interface name if the hardware changed (hypervisor, NIC types, etc.) in a real world example you would not have the second NIC.


Now the problem. The interface name changed to ens192. The NIC is connected in the VM config but it’s not getting an IP. This can happen to both static and DHCP configs.

Ubuntu (netplan)

Ubuntu started using netplan in version 17.10. If your version (check with cat /etc/os-release) is newer than 17.10 any changes made in /etc/network will have no effect or will be lost on reboot.

New interface name

Run ip a to get the new interface name. In this screenshot the interface name is ens192.

ip a


The changed interface is “6” in this screenshot. Yours might be different.

netplan config

The netplan configs are located in /etc/netplan/ each config is a .yaml file.
Most default installs will only have one file. You can type sudo nano /etc/netplan/ and hit tab for autocomplete or run ls /etc/netplan for a list.

ls /etc/netplan

Open the config in nano or your favorite text editor with
sudo nano /etc/netplan/00-installer-config.yaml

sudo nano /etc/netplan/00-installer-config.yaml

Look for the old interface name in netplan config. It’s ens160 in this example.

Change the old interface name to the new interface name from the step above.
Press ctrl+x to exit y to save then enter to save the old filename.

Restart netplan with sudo netplan apply or reboot.

sudo netplan apply

Debian (/etc/network/interfaces)

New interface name

Run ip a to get the new interface name. In this screenshot the interface name is ens224.

ip a

Update interfaces conf

If you don’t have sudo installed run su to switch to root.

Open the /etc/network/interfaces file in nano or your favorite text editor with
nano /etc/network/interfaces

nano /etc/network/interfaces

Change the old interface name to the new interface name from the step above.
Press ctrl+x to exit y to save then enter to save the old filename.

Reboot with systemctl reboot

systemctl reboot