Static IP Address on Ubuntu Server 18.04

After installing the New version Ubuntu Server, we want to set up a static IP address on Ubuntu Server 18.04. And most importantly, Ubuntu has a new method of setting an IP address.

According to the Ubuntu ReleaseNotes, ubuntu 18.04 Bionic Beaver uses Netplan to configure the IP address. It’s network utility for easily configuring the network on a Linux system, and introduced since Ubuntu 17.10.

Basically, netplan uses the YAML script from the ‘/etc/netplan’ directory to generate network configuration to the backend renderer. Currently, netplan support the NetworkManager and systemd-networkd as the backend-render renderer.

In this tutorial, we are going to show you how to a setup IP address on Ubuntu 18.04 Server. We want to set up the static IP address and dynamic DHCP using Netplan networking tool.

Checking Network Interfaces

First of all, we need to check available network interfaces on the system. And linux provides two utilities for that purpose, we can use ‘ifconfig’ or ‘ip’ command.

Check network interfaces using ‘ifconfig’ command.

ifconfig -a

Or check using ‘ip’ command.

ip addr

As a result of two different commands, you can see that the system has two interfaces ‘eth0’ and ‘lo’.

Setup Static IP Address on Ubuntu 18.04

For this example, we want to change the IP address of ‘eth1’ interface with the new static IP address ‘10.5.5.15’. And we will do it by creating a custom netplan configuration.

By default, ubuntu server has a default netplan configuration file ’50-cloud-init.yaml’ on the ‘/etc/netplan’ directory. Go to that directory and backup the default configuration file.

cd /etc/netplan/
mv 50-cloud-init.yaml 50-cloud-init.yaml.original

After that, create a new netplan YAML network configuration.

vim hakase-net.yaml

Add the network details including the network interface, IP address, gateway, and the default resolver IP address.

# This file describes the network interfaces available on your system
# For more information, see netplan(5).
network:
  version: 2
  renderer: networkd
  ethernets:
    eth0:
      dhcp4: no
      addresses: [10.5.5.15/24]
      gateway4:  10.5.5.1
      nameservers:
              addresses: [1.1.1.1, 8.8.8.8]

Save and close the configuration file.

Additionally, detail configurations:

  • renderer – type of renderer used
  • eth0 – the name of the network interface
  • dhcp4 – DHCP configuration of the interface for IPv4
  • addresses – the static IP address
  • gateway4 – default gateway of the IP addresses
  • nameservers – IP address of the resolver

Now apply the custom network changes using the following netplan command.

sudo netplan apply

After that, verify the ‘eth0’ interface and it should have a new static IP address.

ifconfig -a

Finally, the configuration of static IP address on Ubuntu Server 18.04 has been completed.

Setup Dynamic DHCP IP Address on Ubuntu 18.04

To configure the ‘eth0’ interface to use dynamic IP address through DHCP, simply just change the ‘dhcp4’ option on the YAML configuration to ‘yes’.

Edit the network YAML file.

vim hakase-net.yaml

Change the ‘dhcp4’ option to ‘yes’ and delete other lines.

# This file describes the network interfaces available on your system
# For more information, see netplan(5).
network:
  version: 2
  renderer: networkd
  ethernets:
    eth0:
      dhcp4: yes

Save and close the configuration.

After that, apply the network changes to the system and verify the IP address using the following command.

sudo netplan apply
ifconfig -a

And as a result, you will see the ‘eth0’ interface has a different IP address, configured through the DHCP.