Press "Enter" to skip to content

Set Static IP with Netplan on Ubuntu 18.04 Server

I opened up /etc/network/interfaces on an 18.04 VM today and found it contains this message:

# ifupdown has been replaced by netplan(5) on this system.  See
# /etc/netplan for current configuration.

The idea with netplan is that “You simply create a YAML description of the required network interfaces and what each should be configured to do”.  In  /etc/netplan/01-netcfg.yaml I wrote this config, which sets a static IP for a device based on it’s mac address.

network:
  version: 2
  renderer: networkd
  ethernets:
    id0:
      match:
        macaddress: 01:23:45:67:89:00
      gateway4: 192.168.1.1
      addresses: [192.168.23.4/16]
      nameservers:
        addresses: [192.168.1.45]
        search: [foo.co.uk,local]

From the man page id0 is an “opaque ID for physical interfaces, only referred to by other stanzas”.  Here is the equivalent config from /etc/network/interfaces which goes by device name instead of macaddress:

auto ens32
iface ens32 inet static
  address 192.168.23.4
  netmask 255.255.0.0
        network 192.168.0.0
  gateway 192.168.1.1
        dns-nameservers 192.168.1.45
        dns-domain foo.co.uk local

 

Run netplan apply to update the settings immediately.

Be First to Comment

Leave a Reply

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