Changing Ethernet Interface name from ens to eth using netplan

This short post is about changing interface name of your choice from the default ens prefix in the Linux. I have an Ubuntu 18.04 virtual machine running in VMware Fusion 12 Pro. Ubuntu now uses netplan to handle networking configurations, so, the cleanest way to change the names to whatever you want is to tie the name with MAC address in netplan YAML file.

Here I will change the names from ens33 and ens34 to eth0 and eth1 respectively, you can use the name of your choice i.e. wan0, lan0, etc.

Note the MAC addresses of the interfaces

mmalik@crpd:/etc/netplan$ ifconfig
ens33: flags=4163 mtu 1500
inet 192.168.125.133 netmask 255.255.255.0 broadcast 192.168.125.255
inet6 fe80::20c:29ff:fe34:39e0 prefixlen 64 scopeid 0x20
ether 00:0c:29:34:39:e0 txqueuelen 1000 (Ethernet)
RX packets 1218 bytes 116085 (116.0 KB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 883 bytes 125267 (125.2 KB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

ens34: flags=4163 mtu 1500
inet 172.16.127.133 netmask 255.255.255.0 broadcast 172.16.127.255
inet6 fe80::20c:29ff:fe34:39ea prefixlen 64 scopeid 0x20
ether 00:0c:29:34:39:ea txqueuelen 1000 (Ethernet)
RX packets 24 bytes 2208 (2.2 KB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 175 bytes 10756 (10.7 KB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

lo: flags=73 mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10
loop txqueuelen 1000 (Local Loopback)
RX packets 209 bytes 18357 (18.3 KB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 209 bytes 18357 (18.3 KB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

You may transfer the netplan YAML file to your laptop for easy editing else use VIM.

mmalik@crpd:/etc/netplan$ scp 00-installer-config.yaml 192.168.125.1:/Users/mmalik/Downloads
00-installer-config.yaml 100% 414 443.2KB/s 00:00

Check if all indentations are placed correctly at http://www.yamllint.com/

Transfer the file back to VM
mmalik@mmalik-mbp Downloads % scp 00-installer-config.yaml 192.168.125.133:/home/mmalik/
00-installer-config.yaml 100% 459 577.6KB/s 00:00

Move the netplan yaml file to correct location

mmalik@crpd:~$ mv 00-installer-config.yaml /etc/netplan/

Apply the config from the netplan YAML file and reboot the VM.

mmalik@crpd:~$ sudo netplan apply
mmalik@crpd:~$ sudo reboot

Check the interfaces again
mmalik@crpd:~$ ifconfig
eth0: flags=4163 mtu 1500
inet 192.168.125.133 netmask 255.255.255.0 broadcast 192.168.125.255
inet6 fe80::20c:29ff:fe34:39e0 prefixlen 64 scopeid 0x20
ether 00:0c:29:34:39:e0 txqueuelen 1000 (Ethernet)
RX packets 609 bytes 764536 (764.5 KB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 149 bytes 17267 (17.2 KB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

eth1: flags=4163 mtu 1500
inet 172.16.127.133 netmask 255.255.255.0 broadcast 172.16.127.255
inet6 fe80::20c:29ff:fe34:39ea prefixlen 64 scopeid 0x20
ether 00:0c:29:34:39:ea txqueuelen 1000 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 9 bytes 726 (726.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

lo: flags=73 mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10
loop txqueuelen 1000 (Local Loopback)
RX packets 99 bytes 7803 (7.8 KB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 99 bytes 7803 (7.8 KB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: