As many might know, Ubuntu 18.04 LTS uses Netplan for network configuration. Which was added in Ubuntu 17.10 in unpopular move by Canonical. The issue behind it was a bad implementation of ifupdown, which crashed the desktop environment whenever the networking service was restarted.

The new interface files are located in /etc/netplan directory. There are 2 renderers you might be familiar with, NetworkManager and networkd. NetworkManager is usually used in desktop environments while networkd in server. We will be working with networkd only in this example.

Below is a sample file:

# This file is generated from information provided by 
# the datasource.  Changes to it will not persist across an instance. 
# 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:     
    renderer: 
    ethernets:   
        enp0s3:             
            addresses: []             
            dhcp4: true     
    version: 2

Biggest caveat is the spacing in yaml, there should be exactly 4 space intervals, in the example above, properties of network are 4 spaces from start of the line, properties of ethernets are 4 spaces away as well.

Now we need to edit /etc/netplan/50-cloud-init.yaml file and configure our static IP. Open it up in your favorite text editor, we will use nano in our example.

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

Then we need to add your static IP to the config like so:

# This file is generated from information provided by 
# the datasource.  Changes to it will not persist across an instance. 
# 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:
    renderer: networkd 
    ethernets:         
        enp0s3:
            addresses: [192.168.1.2/24]             
            gateway4: 192.168.1.1             
            nameservers:               
                addresses: [8.8.8.8,8.8.4.4]             
            dhcp4: no 
    version: 2

Save your changes and exit. Next, we apply the current config.

sudo netplan apply

The server now should have new IP configured for interface enp0s3. If there are any errors, you can use the following command to narrow down the reason for the error.

sudo netplan --debug apply

If you want to apply multiple IPs to the interface, all you need to do is add another IP to addresses separated by comma, like so:

# This file is generated from information provided by 
# the datasource.  Changes to it will not persist across an instance. 
# 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:
    renderer: networkd 
    ethernets:         
        enp0s3:
            addresses: [192.168.1.2/24, 192.168.1.3/24]             
            gateway4: 192.168.1.1             
            nameservers:               
                addresses: [8.8.8.8,8.8.4.4]             
            dhcp4: no 
    version: 2

That’s it, we are all done.