Netplan

CLI

sudo netplan apply
sudo netplan --debug apply
 
sudo netplan --debug generate
 
networkctl list
# /etc/netplan/01-netcfg.yaml
network:
  version: 2
  renderer: networkd
  ethernets:
    eth0:
      dhcp4: yes
    eth1:
      dhcp4: no
      mtu: 9000
      addresses:
        - 10.0.1.123/24
        - 192.168.1.123/24
      gateway4: 10.0.1.254
      nameservers:
        addresses: [10.0.1.1,8.8.8.8]
        search: [example.com, dev]
      routes:
       - to: 10.5.0.0/16
         via: 10.5.88.1
       - to: 10.8.0.0/25
         via: 10.5.88.1

Enable dhcp on all interfaces

# /etc/netplan/01-netcfg.yaml
network:
  version: 2
  renderer: networkd
  ethernets:
    all:
      match:
        name: enp*f0
      dhcp4: yes
      optional: true
    eno1:
      dhcp4: yes
      optional: true
network:
  version: 2
  renderer: networkd
 
  ethernets:
    eno1:
      dhcp4: no
    eno2:
      dhcp4: no
    eno3:
      dhcp4: no
    eno4:
      dhcp4: no
 
  vlans:
    170:
      accept-ra: no
      id: 170
      link: eno4
 
  bonds:
    bond0:
      dhcp4: no
      interfaces: [eno1,eno2]
      parameters:
        mode: active-backup
        primary: eno1
    bond1:
      dhcp4: no
      interfaces: [enp24s0f0,enp24s0f1]
      parameters:
        mode: 802.3ad
        mii-monitor-interval: 100
        # stp: false
        # forward-delay: 0
 
  bridges:
    br0:
      dhcp4: no
      addresses: [10.0.1.5/24]
      gateway4: 10.0.1.254
      nameservers:
        addresses: [10.0.1.1]
        search: [example.com]
      interfaces: [bond0]
    net1:
      dhcp4: no
    drbd:
      dhcp4: no

enable interface without IP

# cat /etc/netplan/10-eth1.yaml 
network:
  version: 2
  renderer: networkd
  ethernets:
    eth1:
      dhcp4: false
      dhcp6: true
      optional: true

Prevent double default route

https://bugs.launchpad.net/netplan/+bug/1759014
# wget http://archive.ubuntu.com/ubuntu/pool/main/n/netplan.io/netplan.io_0.96-0ubuntu0.18.04.3_amd64.deb -O /tmp/netplan.io_amd64.deb
# dpkg -i /tmp/netplan.io_amd64.deb
 
# Ansible
    - name: Upgrade netplan.io package (Workaround for https://bugs.launchpad.net/netplan/+bug/1759014)
      apt:
        deb: http://archive.ubuntu.com/ubuntu/pool/main/n/netplan.io/netplan.io_0.96-0ubuntu0.18.04.3_amd64.deb
 
sudo echo "deb http://archive.ubuntu.com/ubuntu/ bionic-proposed restricted main multiverse universe" > /etc/apt/sources.list.d/proposed-updates.list
sudo apt update
sudo apt-get install -y netplan.io/bionic-proposed
sudo rm /etc/apt/sources.list.d/proposed-updates.list
sudo apt update
 
network:
  version: 2
  ethernets:
    eth0:
      optional: true
      dhcp4: true
      dhcp4-overrides:
        use-dns: false
        use-routes: false
# cat /etc/netplan/50-cloud-init.yaml 
# network: {config: disabled}
network:
    version: 2
    ethernets:
        ens3:
            dhcp4: true
            match:
                macaddress: 00:11:22:33:44:55
            set-name: ens3
 
 
network:
    version: 2
    ethernets:
        ens3:
            dhcp4: true
            match:
                macaddress: 00:01:02:03:04:05
            set-name: backend
network:
    version: 2
    ethernets:
        enp0s25:
            match:
                macaddress: b8:ae:ed:7d:17:d2
            mtu: 1500
            nameservers:
                addresses:
                - 10.90.90.1
                search:
                - maaslab
                - maas
            set-name: enp0s25

Links
https://netplan.io/reference
https://netplan.io/examples
http://manpages.ubuntu.com/manpages/latest/en/man5/netplan.5.html