Ubuntu netplan static IP address

It has been a few years since I last touched a Linux box. Tonight I decided to install an Ubuntu Server and wanted to give it a static IP address. As I went to /etc/network and wanted to edit the interfaces file, I realised that things have changed. Now you configure the NICs using netplan.

So I fired up putty after reading some examples on how to do this and got hit by this error when trying to apply the configuration:

Invalid YAML at /etc/netplan/eth.yaml line 10 column 0: found character that cannot start any token

Turns out that I had used tab to do indents of the config. I change my tabs to spaces and it all worked out. My config is this now:

network:
    version: 2
    ethernets:
        ens160:
          addresses: [ "10.10.10.22/22" ]
          gateway4: 10.10.10.1
          nameservers:
            addresses: [8.8.8.8, 9.9.9.9]

It is applied using:

sudo netplan apply

If you do not receive any errors verify with

ifconfig
Jacob Zartmann avatar
Jacob Zartmann
Passionate Network Engineer thriving for challenges and knowledge.