How to set up a static IP on Ubuntu 20.04

This article demonstrates how to set up Ubuntu Server 20.04 with a static IP address after the server installation which defaults to DHCP IP addressing.

In this latest iteration of Ubuntu Server, Canonical decided to use netplan to manage the network configuration and therefore the static IP address set up is a bit different. I expect that you have a Ubuntu Server 20.04 installed and running and if you need help setting one one follow this article.

static IP
static IP

Lets get started and have a look at the current network configuration by executing the following command:

ip addr

this should display something similar like the following screenshot.

ip addr commmand to display current network setup
ip addr commmand to display current network setup

Since the use on netplan one has to edit yaml files which netplan uses to configure the network interface. Execute the following command:

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

and it should look like this:

YAML config file for netplan DHCP configuration.
YAML config file for netplan DHCP configuration.

As you clearly can spot this is set up to use DHCP version 4 to automatically configure the network card. Lets make changes to it and set up the IP Address to be 192.168.69.90, the Gateway to be 192.168.69.1 and Name Servers to be 8.8.8.8 & 8.8.4.4. Make change so it looks like the following:

YAML config file for netplan static IP configuration
YAML config file for netplan static IP configuration

In the next step save the file and try out the new network configuration. Run the following command:

sudo netplan try

After executingthat command you should see something like the following screenshot:

Netplan trying the new configuration.
Netplan trying the new configuration.

Hit enter to accept that configuration and let run the following commands to see that all is still working.

ip addr

to check the new configuration was applied

ping 192.168.69.1

ping the internal gateway to verify network communication is working internally

ping 8.8.8.8

ping an external ip address to verify external network communication is working

netlookup ubuntu.com

query the public DNS to verify that this part of the network configuration is working as well. If everything is responding as expected without any errors we can go ahead and apply the new netplan configuration for good with the following command:

sudo netplan apply

Lets reboot the server and see that it is indeed all configured correctly and applied even upon reboot of the server. After the reboot is done log back in and run:

ip addr

it should look like the following:

YAML config file after successful application
YAML config file after successful application

As you can see even after a server reboot the configuration has been successfully applied.

Conclusion

As you can see the new netplan network configuration is fairly easy and simple. I like it quiet a lot especially the part that you can try it out before completely apply it. If you like to read more about netplan read here. Hopefully this article was useful. Please leave a comment and perhaps provide suggestion for future articles.

Ciao!