Home Compiling tools Network configuration in Ubuntu 18.04 LTS using netplan

Network configuration in Ubuntu 18.04 LTS using netplan

by SupportPRO Admin

With Ubuntu 18.04 onwards, configuring IP addresses stands different from the older versions. When comparing with the previous versions the Ubuntu is using a new utility called Netplan – another order line arrange design utility, to arrange an IP address.

Netplan has been presented by Ubuntu engineers in Ubuntu 17.10 where we no longer use the “interfaces” file to configure IP address but does the task using a YAML file with all default arrangement documents found under /etc/netplan/ directory. In this blog, we will check on how to design static and dynamic IP address in Ubuntu 18.04 LTS server.

Netplan’s design documents utilize the YAML format where all /{lib,etc,run}/netplan/*.yaml are considered. Lexicographically later records (paying little mind to in which index they are) alter (new mapping keys) or override (same mapping keys) past ones.

A document in /run/netplan totally shadows a record with the same name in /etc/netplan, and a file in both of those directories shadows a file with a similar name in /lib/netplan.

Distribution installers, cloud instantiation, image works for specific devices, or some other method to convey a working framework put its ideal system arrangement into YAML setup file(s). During initial boot, the netplan “network renderer” runs yaml files under netplan directory and saves the configuration to /run to assign control of devices to the specified networking daemon.

  • Designed devices get taken care of by systemd-networkd as a matter of course, except if expressly set apart as oversaw by a particular renderer (NetworkManager)
  • Devices that are not mentioned by the network config are not worked upon.
  • Usable in initramfs (not many conditions and quick)
  • No persistent generated config, just only the unique YAML config
  • Parser holds-up several config documents to permit applications like libvirt or lxd to acheive required network config (virbr0, lxdbr0), or to alter the global default policy to use NetworkManager for everything.
  • Flexibility to change backend or policy later or adjust to removing NetworkManager is retained, as the generated configuration is transitory.

Starting with Ubuntu 17.10 and on (this includes Ubuntu 18 of course), Ubuntu developers have switched from using the old /etc/network/interfaces file to using the new YAML based /etc/netplan method to adding IPs and setting up bonding.

To add new IPs to an Ubuntu system using the netplan package, you need to do the following:

  1. Go to the netplan directory: cd /etc/netplan
  2. In the netplan directory, you can see what files you have, typically it will be something like 01-netcfg.yaml. Now open the file using your favorite editor, we will use vim: vim 01-netcfg.yaml

Note: adjust the file name to whatever file you have in your environment.

The file should look like something like this:

Note: Again, all IPs and domains are random and are used for this example only, you will have different values on your instance.

This particular setup has two live IPs: 192.168.0.2 and 172.16.0.2. What if you need to also add 172.16.0.3 and 172.16.0.4 Ips? You would simply add them to the ‘addresses’ line like so:

addresses: [ 192.168.0.2/32, 172.16.0.2/16, 172.16.0.3/16, 172.16.0.4/16]

Make sure to use the correct format, using the CIDR notation.

  1. What if you need to use two different gateways because your IP blocks are using different gateways?

For instance, the 172.16.0.2 IP needs to use 172.16.0.1 gateway to work properly. In this case, you need to comment out the ‘gateway4’ line and add a ‘routes’ block as mentioned below:

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Please make sure to use proper indentation or it won’t work. YAML requires this.

  1. After you are done, save the file and then restart and apply the network: netplan apply
  1. Check to ensure all IPs show: ip addr

This will list all active IPs and they should now be pingable and usable upon boot as well.

How to Configure a Static IP Address In Ubuntu 18.04 LTS Server

The default network configuration file is:

$ ls /etc/netplan/

50-cloud-init.yaml

Let’s check the contents of this file:

As you can see, enp0s3 and enp0s8 are the two network cards that are configured to accept IPs from the DHCP server.

Note: Before making any changes in this file, let us backup it.

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

  1. Now, Open the default network configuration file in any of the editors.

$ sudo nano /etc/netplan/50-cloud-init.yaml

Update the corresponding file by adding the IP, netmask, gateway and DNS server. For a guide, I am going to use the following network settings.

  • IP address for enp0s3 : 192.168.225.50
  • IP address for enp0s8 : 192.168.225.51
  • Gateway : 192.168.225.1
  • Netmask : 255.255.255.0
  • DNS servers : 8.8.8.8 and 8.8.4.4.

Below mentioned is the result after configuring all network settings, this is how the contents of 50-cloud-init.yaml file look like.

Also, we do not use a different line to define netmask (255.255.255.0) in Ubuntu version 18.04.

For instance, in the old Ubuntu versions, we configure IP and netmask like below,

address = 192.168.225.50

netmask = 255.255.255.0

With netplan, we combine those respective two lines with a single line as shown below:

addresses : [192.168.225.50/24]

3. After adding the range. Save and close the file.

Apply the network configuration using command:

$ sudo netplan apply

We can run the below mentioned to investigate and check what is the problem in the configuration.

$ sudo netplan –debug apply

Sample output reference,

Leave a Comment