Static Netplan template Ubuntu 20.04

Written by

in

, ,

Editor’s note (2026): `gateway4` shown below is deprecated in current Netplan releases — it still works but throws a deprecation warning. The current-style syntax is a `routes:` block instead. Both are shown here.

I like to leave a dhcp server up so that when I spin up a virtual machine to tinker with it’ll grab that IP and I’ll be on my marry way.

If in the event that I want to later statically assign it (the ip) just use the following template and adjust.

Older / still-working style (deprecated):

network:
  ethernets:
    ens18:
      addresses:
      - 172.16.0.2/24
      nameservers:
        addresses:
        - 172.16.0.2
        - 8.8.8.8
        search:
        - domain.com
      gateway4: 172.16.0.1
  renderer: networkd
  version: 2

Current-style syntax using a routes block instead of gateway4:

network:
  ethernets:
    ens18:
      addresses:
      - 172.16.0.2/24
      nameservers:
        addresses:
        - 172.16.0.2
        - 8.8.8.8
        search:
        - domain.com
      routes:
      - to: default
        via: 172.16.0.1
  renderer: networkd
  version: 2

Comments

Leave a Reply

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