Netplan

CLI

sudo netplan apply
sudo netplan --debug apply
 
sudo netplan --debug generate
 
networkctl list

Examples
https://netplan.readthedocs.io/en/latest/examples/
https://netplan.io/examples
https://github.com/canonical/netplan/tree/main/examples
https://cloudinit.readthedocs.io/en/latest/reference/network-config-format-v2.html

# /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
     routes:
        - to: default
          via: 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*[f,s]0
      dhcp4: yes
      optional: true
    eno1:
      dhcp4: yes
      optional: true
 
network:
  version: 2
  renderer: networkd
  ethernets:
    all:
      match:
        macaddress: 00:11:22:33:44:55
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]
      mtu: 9000
      parameters:
        mode: active-backup
        primary: eno1
    bond1:
      dhcp4: no
      interfaces: [enp24s0f0,enp24s0f1]
      parameters:
        mode: 802.3ad
        mii-monitor-interval: 100
        transmit-hash-policy: layer3+4
        # stp: false
        # forward-delay: 0
 
  bridges:
    br0:
      dhcp4: no
      addresses: [10.0.1.5/24]
      routes:
        - to: default
          via: 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
 
 
      dhcp4-overrides:
        route-metric: 100
      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

Configure NIC name by MAC

network:
  version: 2
  ethernets:
    port1:
      dhcp4: true
      match:
        macaddress: 00:11:22:33:44:55
      set-name: port1

SR-IOV

network:
  version: 2
  renderer: networkd
 
  ethernets:
    eno1:
      dhcp4: yes
    eno2:
      virtual-function-count: 4
    vf1:
      match:
        name: eno2v[0-3]
      dhcp4: no
      #    eno2v0:
      #dhcp4: no
       #mtu: 9000
 
  vlans:
    stage-mgmt:
      id: 3649
      #link: eno2v0
      link: vf1
      dhcp4: yes

Blackhole

      routes:
        - to: 10.9.20.0/24
          via: 10.9.49.1
        - to: 10.9.0.0/16
          via: 0.0.0.0
          type: blackhole

Wifi

network:
  version: 2
  wifis:
    wlan0:
      access-points:
        "FRITZ!Box Fon WLAN 5490":
          password: 1234567890
      dhcp4: true

Mulpiple default route with netplan
https://netplan.readthedocs.io/en/latest/examples/#how-to-configure-source-routing

# networks
network_1 ens3: 10.0.10.0/24
network_2 ens8: 10.0.20.0/24
 
# /etc/netplan/50-cloud-init.yaml
network:
  version: 2
  renderer: networkd
  ethernets:
    ens3:
      dhcp4: yes
    ens8:
      dhcp4: yes
      dhcp4-overrides:
        use-routes: false
      routes:
        - to: default
          via: 10.0.20.1
          table: 200
        - to: 10.0.20.0/24
          via: 10.0.20.1
          table: 200
      routing-policy:
        - from: 10.0.20.0/24
          table: 200

Parameter
https://netplan.io/reference

Restart

systemctl reset-failed
systemctl daemon-reload 
systemctl restart systemd-networkd.socket
systemctl start systemd-networkd.service #netplan-ovs-cleanup.service
netplan generate
netplan apply

Debug / logs

journalctl --no-pager -lu systemd-networkd

Links
https://netplan.io/reference
http://manpages.ubuntu.com/manpages/latest/en/man5/netplan.5.html
https://getlabsdone.com/how-to-configure-netplan-network/