How To Configure Static IP on Ubuntu Server 20.04

By configuring a static IP address to your Ubuntu server machine you are simply assuring that the address won’t change when the machine reboots. This is useful specially if you are self hosting services and you want to ensure that they are always available.

Access your host and edit the configuration

SSH into your host and edit the configuration file located at /etc/netplan/00-installer-config.yaml (I am using nano):

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

Inside, comment out everything by adding a # to the front so we can save the default configuration in case we want to revert later:

# This is the network config written by 'subiquity'
#network:
#  ethernets:
#    ens160:
#      dhcp4: true
#  version: 2

Now add the following making sure to edit to fit your environment:

# This is the network config written by 'subiquity'
network:
  ethernets:
    ens160:
      addresses:
      - 192.168.141.21/24
      gateway4: 192.168.141.1
      nameservers:
        addresses:
        - 192.168.141.1
  version: 2

The end file should look like this:

# This is the network config written by 'subiquity'
#network:
#  ethernets:
#    ens160:
#      dhcp4: true
#  version: 2

# This is the network config written by 'subiquity'
network:
  ethernets:
    ens160:
      addresses:
      - 192.168.141.21/24
      gateway4: 192.168.141.1
      nameservers:
        addresses:
        - 192.168.141.1
  version: 2

Save and reboot. You have now successfully configured your Ubuntu server with a static IP and will be accessible at the 192.168.141.21 IP address.

Leave a Reply

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