Configure Static IP on Ubuntu 18.04 LTS

Configuring Static IP with Netplan on Ubuntu

Below you will find the steps to configure a static IP address with Netplan on Ubuntu. The netplan config files are located at /etc/netplan and the default configuration file is /etc/netplan/01-netcfg.yaml

Open the network config file with an editor such as nano:

sudo nano /etc/netplan/01-netcfg.yaml

Netplan uses Python for it's configuration syntax so it's important that all line indentation is correct.

In the example below, we'll be using a static IP address of 172.16.253.200 on the first network interface ens33 and a gateway IP of 172.16.253.1. This configuration uses CloudFlare DNS in conjunction with Google DNS.

network:
version: 2
renderer: networkd
ethernets:
ens33:
dhcp4: no
dhcp6: no
addresses: [172.16.253.200/24]
gateway4: 172.16.253.1
nameservers:
addresses: [1.1.1.1,8.8.8.8]

Once all your changes have been made, you can apply them by running:

sudo netplan apply

Configuring a DHCP address with Netplan

If you'd like to configure your Ubuntu server to run on DHCP (on both ipv4 and ipv6) instead of a static IP address, see the configuration below.

This file describes the network interfaces available on your system

For more information, see netplan(5).

network:
version: 2
renderer: networkd
ethernets:
ens33:
dhcp4: yes
dhcp6: yes

Don't forget to run the command to apply the changes after you're done