Wednesday, February 03, 2021

Linux Networking with Netplan: Examples, etc.

This is not meant to be a prose-y post.  It's really just a handful of examples to illustrate how to use netplan to implement host networking in Linux.  Remember to use sudo netplan generate to syntax-check your changes, and sudo netplan apply to implement them.

The netplan reference is located at https://netplan.io/reference/

Using DHCP

network:
  version: 2
  renderer: NetworkManager
  ethernets:
    eth0:
      dhcp4: yes
      dhcp6: yes

Assigning a static IP address (with gateway, DNS, etc.)

network:
  version: 2
  renderer: NetworkManager
  ethernets:
    eth0:
      dhcp4: no
      addresses: [192.168.100.118/24]
      gateway4: 192.168.100.1
      nameservers:
        search: [lab]
        addresses: [1.1.1.1, 9.9.9.9]


Creating a bond interface (also illustrates a static route)

network:
  version: 2
  renderer: NetworkManager
  ethernets:
    eth1:
      dhcp4: no
    eth2:
      dhcp4: no
  bonds:
    bond0:
      interfaces: [eth1, eth2]
      addresses: [172.24.100.116/24]
      dhcp4: no
      dhcp6: no
      routes:
      - to: 172.16.0.0/12
        via: 172.24.100.1
      parameters:
        mode: 802.3ad
        lacp-rate: fast
        transmit-hash-policy: layer3+4
        mii-monitor-interval: 100

Creating a VLAN-tagged interface

network:
  version: 2
  renderer: NetworkManager
  ethernets:
    eth1:
      dhcp4: no
      dhcp6: no
  vlans:
    eth1.101:
      id: 101
      link: eth1
      addresses: [172.24.101.118/24]
      routes:
      - to: 172.16.0.0/12
        via: 172.24.101.1
    eth1.102:
      id: 102
      link: eth1
      addresses: [172.24.102.118/24]
      routes:
      - to: 172.16.0.0/12
        via: 172.24.102.1