Renaming a Network Interface in Ubuntu 18.04 on IBM Cloud
Renaming a Network Interface in Ubuntu 18.04 on IBM Cloud to eth0
For a project I'm working on, I have a requirement to spin up a VM in IBM Cloud, running Ubuntu 18.04 and with a very specific requirement of having an interface named eth0
(I will be running EVE-NG on this VM). The VM I am working with has a default interface name of ens3
, which I want to change to eth0
.
There are a few steps involved to make this change:
- Get the MAC address for the interface
- Add a rule in
70-persistent-net.rules
- Rename the interface in
/etc/netplan
- Persist the interface name change across reboots
- Switch from
Predictable Network Interface Names
toPersistent Names
scheme - Reboot the VM
Step 1: Get the Interface MAC Address
Issue the ifconfig
command (shown in the snippet below) and locate the ens3
interface from the output. In this example, the MAC address is 02:01:fb:33:37:bb
root@eve-ng:~# ifconfig
ens3: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 10.240.69.254 netmask 255.255.252.0 broadcast 10.240.71.255
inet6 fe80::1:fbff:fe33:37bb prefixlen 64 scopeid 0x20<link>
ether 02:01:fb:33:37:bb txqueuelen 1000 (Ethernet)
RX packets 9045 bytes 122655341 (122.6 MB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 6315 bytes 915074 (915.0 KB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
Step 2: Add a Rule in "70-persistent-net.rules"
Device management in Linux is handled by the udev
daemon. The udev
deamon uses MAC addresses to assign persistent names to interfaces. With that in mind, the next step is to cd
to the /etc/udev/rules.d
directory and check if a file called 70-persistent-net.rules
exists. If it doesn't, then create the file and add the following to it, being sure to replace <INTERFACE_MAC_ADDRESS>
with the MAC address of your interface (e.g. 02:01:fb:33:37:bb
), and <NEW_INTERFACE_NAME>
with the new interface name (e.g. eth0
):
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}==“<INTERFACE_MAC_ADDRESS>”, NAME=“<NEW_INTERFACE_NAME>”
So, for my particular use case, I added the following entry to my 70-persistent-net.rules
file:
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="02:01:fb:33:37:bb", NAME=“eth0”
Step 3: Rename the Interface in "/etc/netplan"
The next step is to cd
to /etc/netplan
and see what file is there. In my case, I have a file in that directory called 50-cloud-init.yaml
. The contents of this file are pasted below:
# This file is generated from information provided by the datasource. Changes
# to it will not persist across an instance reboot. To disable cloud-init's
# network configuration capabilities, write a file
# /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg with the following:
# network: {config: disabled}
network:
ethernets:
ens3:
dhcp4: true
match:
macaddress: 02:01:fb:33:37:bb
set-name: ens3
version: 2
Edit this file and replace any instances of the original interface name (e.g. ens3
) with the new desired interface name (e.g. eth0
). After making these changes, my 50-cloud-init.yaml
file looked like this:
# This file is generated from information provided by the datasource. Changes
# to it will not persist across an instance reboot. To disable cloud-init's
# network configuration capabilities, write a file
# /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg with the following:
# network: {config: disabled}
network:
ethernets:
# original value: ens3
eth0:
dhcp4: true
match:
macaddress: 02:01:fb:33:37:bb
# original value: ens3
set-name: eth0
version: 2
Step 4: Persist the Interface Name Change Across Reboots
In Step 3 above, note the comments at the very top of the 50-cloud-init.yaml
file:
# This file is generated from information provided by the datasource. Changes
# to it will not persist across an instance reboot. To disable cloud-init's
# network configuration capabilities, write a file
# /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg with the following:
# network: {config: disabled}
On this IBM Cloud VM, the changes made to the 50-cloud-init.yaml
file will not persist across reboots. Following the instructions in the comments, create a new file in /etc/cloud/cloud.cfg.d
called 99-disable-network-config.cfg
and add the following single line:
network: {config: disabled}
Step 5: Switch From "Predictable Network Interface Names" to "Persistent Names" Scheme
Beginning with version 197, systemd/udev
automatically assigns predictable names for all network interfaces (e.g. "ens1"), a scheme referred to as "Predictable Network Interface Names". Newer Linux distributions use this scheme, which allows for interfaces to be named in a reproducible way. This is in contrast to the traditional "Persistent Names" scheme, which assigned interface names (beginning with "eth0", "eth1", etc.) in the order in which the interfaces were probed by the drivers. As a result, the "Persistent Names" scheme does not assign interface names in a reproducible way because the order in which driver probing occurs is not predictable. This was the reason for moving to the "Predictable Network Interface Names" scheme.
Edit the /etc/default/grub
file and replace the line GRUB_CMDLINE_LINUX=""
with the following:
GRUB_CMDLINE_LINUX="net.ifnames=0 biosdevname=0"
After this, be sure to apply the settings by issuing the update-grub
command.
Step 6: Reboot the VM
Finally, reboot the VM. When the VM comes back, verify that the changes were applied by issuing the ifconfig
command and verifying that the interface has been renamed to eth0
:
root@eve-ng:~# ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 10.240.69.254 netmask 255.255.252.0 broadcast 10.240.71.255
inet6 fe80::1:fbff:fe33:37bb prefixlen 64 scopeid 0x20<link>
ether 02:01:fb:33:37:bb txqueuelen 1000 (Ethernet)
RX packets 63 bytes 9849 (9.8 KB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 59 bytes 9647 (9.6 KB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
-- Jag --