Configure static IP address on Ubuntu 20.04

Amelye Chatila
2 min readJul 3, 2021

--

At some point you will need a static IP address on your Linux server or Virtual Machine. One of the main reason to do so is having a convenient remote access to your server or VM.

Ubuntu 18.04 LTS and Ubuntu 20.04 LTS has switched to Netplan for configuring network interfaces and it’s installed by default. Netplan is YAML based configuration system.

Static IP address on Ubuntu 20.04

Here we are going to configure a static IP address on Ubuntu 20.04. Edit a configuration file located under /etc/netplan/ the default file name is 00-installer-config.yaml .

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

One Static IP Address

The network interface to configure is enp0s8 and the network is 192.168.43.0/24 you can replace these with yours.

network:
version: 2
ethernets:
enp0s8:
dhcp4: false
addresses:
- 192.168.43.110/24
gateway4: 192.168.43.1
nameservers:
addresses: [8.8.8.8, 8.8.4.4]

Multiple Static IP Addresses

You add another block of the interface. In this case we added an interface enp0s3 with network of 192.168.0.0/24 you can replace these with yours.

network:
version: 2
ethernets:
enp0s8:
dhcp4: false
addresses:
- 192.168.43.110/24
gateway4: 192.168.43.1
nameservers:
addresses: [8.8.8.8, 8.8.4.4]
enp0s3:
dhcp4: false
addresses:
- 192.168.0.110/24
gateway4: 192.168.0.1
nameservers:
addresses: [8.8.8.8, 8.8.4.4]

Testing the Changes

Netplan gives you an option to test the new configuration before making it permanent. In case the configuration fails; the changes will be discarded in 120 seconds. This feature is good when working on live/production system that are remote.

sudo netplan try

Applying the Changes

To apply the changes made save the file, exit the editor and run below command.

sudo netplan apply

Once the command is successful then you have your static IP address set.

--

--

Amelye Chatila

Software Engineer, Linux Enthusiast, Cloud Practitioner, and Tech Content Writer.