Setup Multiple vNICs on an OpenStack-Based Ubuntu 18.04 VM

Introduction

If you need to add a secondary vNIC to an existing OpenStack-based Ubuntu 18.04 virtual machine (VM), here’s a handy guide. There are some ways this process can vary, but using the steps below will help you keep all your vNICs intact--even through a restoration process. Check out how below:

Prerequisites

Before you begin, make sure you have the 18.04 version of Ubuntu installed, as well as OpenStack.

Start Here

Create a port on the desired OpenStack network. This can be done via Horizon GUI or CLI.

At this time, you can use a static IP and/or MAC address, or let OpenStack assign them.

Attach the port created in step 1 to the VM.

Log on to the VM. Check ifconfig and note the identifiers of any existing interfaces.

ubuntu@dualnic-test-2:~$ ifconfig -a

Navigate to the netplan directory.

ubuntu@dualnic-test-2:~$ cd /etc/netplan/

In the netplan directory, there should be a file named 50-cloud-init.yaml. Make a copy of this file and rename it. The name can be anything as long as you include “.yaml” at the end.

ubuntu@dualnic-test-2:/etc/netplan$ sudo cp 50-cloud-init.yaml secondary-nic.yaml

Open the newly created file in an editor of your choice.

ubuntu@dualnic-test-2:/etc/netplan$ sudo vim secondary-nic.yaml

The contents of the file should look 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:
ens3:
dhcp4: true
match:
macaddress: fa:16:3e:4c:54:7e
set-name: ens3
version: 2

There are a few changes we need to make to the file.

Move the line “version: 2” to above the “ethernets:” line
Add the line “dhcp-overrides:” under “dhcp: true”
Add the line “route-metric: 200” under “dhcp-overrides:”
Change the “macaddress:” value to the MAC address of the port created in Step 1.
Change the “set-name:” value and “ens3” to ensX. X should not match any of the other interfaces noted in Step 3.
The file should look like this after the changes:

# 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:

version: 2
ethernets:
ens4:
dhcp4: true
dhcp4-overrides:
route-metric: 200
match:
macaddress: fa:16:3e:2b:f9:41
set-name: ens4

Reboot the VM.

Conclusion

Now you know how to create multiple vNICs that you can rely on even through backups. This will help keep your config files safe, as well as organize your /etc/netplan/ directory.
However, if you come across any problems following the above guide, let us at Awnix know, and we would be happy to help!

**IMPORTANT** When performing any type of restore of the VM, the vNICs/ports MUST be attached DURING the VM creation.

Leave a Comment