ubuntu logo

How to configure a static IP address on Ubuntu 20.04

Spread the love

How to configure a static IP address on Ubuntu 20.04:

It is a good idea to set a static or fixed ip address to a server so that you can guarantee that the machine will always have the same ip address to make it easier to connect to. I prefer to set a static ip dynamically using my dhcp server but if you prefer to add a static IP address then this can easily be done using the following process:

Set a static IP address:

Find the correct interface name:

Open a terminal and run the following command:

ip a
How to configure a static IP address on Ubuntu 20.04

In the example above the network card is eth0 as it is the only interface with an ip address.

Backup the networking file

It is a good idea to back up the networking file before you make any changes so that it can be quickly reverted if things go wrong. Run the following command to make a backup copy of the file:

sudo cp /etc/netplan/50-cloud-init.yaml /etc/netplan/50-cloud-init.yaml.bak

This will create a file called 00-installer-config.yaml.bak in the /etc/netplan/ folder in case you need it.

Edit the 00-installer-config.yaml file to set the static IP Address

Edit the 00-installer-config.yaml file in your desired editor

vim /etc/netplan/50-cloud-init.yaml
Initial Ubuntu Server 20.04 setup on a freshly installed Ubuntu 20.04 server

If your server is set to dhcp then you will see something like:

Initial Ubuntu Server 20.04 setup on a freshly installed Ubuntu 20.04 server

Edit the file to look something like:

Save the file.

Initial Ubuntu Server 20.04 setup on a freshly installed Ubuntu 20.04 server
Initial Ubuntu Server 20.04 setup on a freshly installed Ubuntu 20.04 server

Apply the changes:

sudo netplan apply
Initial Ubuntu Server 20.04 setup on a freshly installed Ubuntu 20.04 server

The server will then be using the new address. If you were connected via ssh you will have to open a new session and connect to the NEW IP ADDRESS:

Initial Ubuntu Server 20.04 setup on a freshly installed Ubuntu 20.04 server

The server will now use this address every time it is rebooted from now on.

To revert the changes you just need to do the following:

Over write the edited file with the backup file:

sudo cp /etc/netplan/50-cloud-init.yaml.bak /etc/netplan/50-cloud-init.yaml
Initial Ubuntu Server 20.04 setup on a freshly installed Ubuntu 20.04 server

Reload netplan:

sudo netplan apply
Initial Ubuntu Server 20.04 setup on a freshly installed Ubuntu 20.04 server

The server will now be configured for dhcp and should have its old ip address again:

Initial Ubuntu Server 20.04 setup on a freshly installed Ubuntu 20.04 server

The server is now ready to install what ever software that you would like to install. For some ideas of what to install go to our Ubuntu Section of the site.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top