notmayo

Cloud Engineer & Sysadmin, Homelabber and Plex media enthusiast

Ubuntu 18.04 LTS – Setting a static IP Address

With this specific Ubuntu release, comes an entirely new way to set or change a static IP address. from 16.04 LTS. Let’s get started.

Open up a terminal window, and let’s get your network interface.

user@hostname:~# ip a
1: lo: mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever inet6 ::1/128 scope host valid_lft forever preferred_lft forever 2: ens160: mtu 1500 qdisc mq state UP group default qlen 1000 link/ether 00:50:55:5e:f5:5f brd ff:ff:ff:ff:ff:ff inet 10.10.10.243/23 brd 10.10.11.255 scope global ens160 valid_lft forever preferred_lft forever inet6 fe85::250:565f:fe5e:fd5f/64 scope link valid_lft forever preferred_lft forever

Now that we have figured out what network interface we are going to work with, let’s change into the /etc/netplan directory.

user@hostname:~# cd /etc/netplan

Verify that there is no file named 01-netcfg.yaml in the directory.

user@hostname:~# ls -l

Create the 01-netcfg.yaml file. If this file exists, skip this step and edit it instead.

user@hostname:~# sudo touch 01-netcfg.yaml

Now that the file exists, let’s add our configuration.

user@hostname:~# sudo vi /etc/netplan/01-netcfg.yaml

Modify this config to your desired network details and network interface. YAML/YML files require indenting, and for the indenting to be consistent. VI will automatically indent correctly if you use the TAB key. Example below:

network:
        version: 2
        renderer: networkd
        ethernets:
                ens160:
                        dhcp4: no
                        addresses: [10.10.10.243/23]
                        gateway4: 10.10.10.1
                        nameservers:
                                addresses: [10.10.10.21,10.10.10.2]

Now, let’s restart the network stack.

user@hostname:~# sudo netplan apply

Now verify connectivity. For troubleshooting, try this command:

user@hostname:~# sudo netplan –debug apply