Skip to main content

Ubuntu Server Network Configuration Using Netplan

Hands-On Lab

 

Photo of Michael Christian

Michael Christian

Course Development Director in Content

Length

00:30:00

Difficulty

Intermediate

In this Hands-on lab, we'll get to practice what we've gone over about using YAML files and Netplan to configure a network interface in Ubuntu 18.04. Understanding Netplan, and how it uses YAML for configuration, gives us an additional option in how we configure the network interface.

What are Hands-On Labs?

Hands-On Labs are scenario-based learning environments where learners can practice without consequences. Don't compromise a system or waste money on expensive downloads. Practice real-world skills without the real-world risk, no assembly required.

Ubuntu Server Network Configuration Using Netplan

Introduction

In this Hands-on lab, we'll get to practice what we've gone over about using YAML files and Netplan to configure a network interface in Ubuntu 18.04.

Understanding Netplan, and how it uses YAML for configuration, gives us an additional option in how we configure the network interface.

Solution

We have been provided with an Ubuntu 18.04 LTS Server that has two network interfaces. One interface is already configured, and we must use Netplan to configure the other.

Determine the Network Information

As the first step, we will need to determine the interfaces on the host, and figure out which one is already configured:

$ ip addr show

Make a note of the MAC address of eth1.

Then take a look at the default Netplan file provided by the installer:

cat /etc/netplan/50-cloud-init.yaml

Create a Netplan YAML File for the New Interface

Using the existing file as a template, duplicate it:

$ sudo cp /etc/netplan/50-cloud-init.yaml /etc/netplan/51-cloud-init.yaml

Then modify the new file to match the interface eth0, but make eth0 say eth1, and use the correct MAC address:

network:
   version: 2
   ethernets:
       eth1:
           dhcp4: true
           match:
               macaddress: MAC_ADDRESS_OF_ETH1
           set-name: eth1

Test and Apply the New Netplan Configuration

Test the configuration using:

$ sudo netplan try

Press [ENTER] to accept the new configuration.

Conclusion

If we run ip addr show again, we'll see that the second NIC is now up and running, active on a second subnet. That's all we wanted. Congratulations!