How to configure static ipv4 in ubuntu with netplan

Here the steps to configure a static IP address with Netplan.

The Netplan configuration files are located in the directory /etc/netplan/.

The default configuration file is /etc/netplan/01-netcfg.yaml.

Open the network config file with an editor.

The netplan configuration filename differs, depending on the Ubuntu version.

in Ubuntu 20.04:

sudo nano /etc/netplan/00-installer-config.yaml

Ubuntu 18.04:

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

The configuration syntax is in Python programming language (.yaml format), so the indentation of the lines is important!

The content of the file is the same on Ubuntu 20.04 and 18.04.

Here is an example of a static IPv4 address 192.168.1.100 on the first network interface ens33 and gateway IP 192.168.1.1. The server will use the free Google DNS servers 8.8.8.8 and 8.8.4.4 to for name resolving.

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

Or as Screenshot from an Ubuntu server:

save and quit.

and you might want to test your connections with the below command.

sudo netplan apply

and it all is well then you can confirm the configuration with the below command.

sudo netplan apply

Or use it with the --debug switch to get some useful output if parsing of the netplan config file was successful.

sudo netplan --debug apply

Thank you

-Owlabz