Static IP address for Ubuntu Server 18.04 “netplan”

If you are using Ubuntu Server version 18.04 LTS and want to configure a static IP address, the procedure has changed for network interface configuration.

We used to configure /etc/network/interfaces but now the system uses something called netplan. If you try to configure the old “interfaces” file, it will point you to this new netplan network configuration.

Here’s how we change the network interface to use a static IP address. Edit “50-cloud-init.yaml“, replacing the text with the text below. Replace the IP address with your own (192.168.1.100 used as an example) and then save:

sudo nano /etc/netplan/50-cloud-init.yaml
# This file is generated from information provided by
# the datasource.  Changes to it will not persist across an instance.
# To disable cloud-init's network configuration capabilities, write a file
# /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg with the following:
# network: {config: disabled}
network:
    ethernets:
        enp0s3:
            addresses: [192.168.1.100/24]
            gateway4: 192.168.1.1
            nameservers:
              addresses: [8.8.8.8,8.8.4.4]
            dhcp4: no
    version: 2

Apply the changes and then reboot.

sudo netplan apply
sudo reboot
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s