PG1X WIKI

My Knowledge Base

User Tools

Site Tools


tech:server:linux:ubuntu:networking:netplan:netplan

Netplan

Using Netplan. YAML based networking configuration.

Default Generated File Name Examples

  • /etc/cloud/cloud.cfg.d/50-curtin-networking.cfg
  • /etc/netplan/50-cloud-init.yaml
  • /etc/netplan/01-netcfg.yaml
  • /etc/netplan/01-network-manager-all.yaml

Default Configuration Examples

/etc/netplan/01-netcfg.yaml
# This file describes the network interfaces available on your system
# For more information, see netplan(5).
network:
  version: 2
  renderer: networkd
  ethernets:
    eno2:
      dhcp4: yes
      dhcp6: yes
/etc/netplan/50-cloud-init.yaml
network:
  ethernets:
    ens33:
      addresses: []
      dhcp4: true
      optional: true
  version: 2

Configuration Workflow

sudo vim /etc/netplan/01-netcfg.yaml
sudo netplan apply

Recipes

Static IP(IPv4)

This networking renderer assume systemd-networkd.

sudo mv /etc/netplan/50-cloud-init.yaml /etc/netplan/01-netcfg.yaml
sudo vim /etc/netplan/01-netcfg.yaml
/etc/netplan/01-netcfg.yaml
network:
 version: 2
 renderer: networkd
 ethernets:
   ens33:
     dhcp4: no
     dhcp6: no
     addresses: [ 172.16.2.222/24 ]
     gateway4: 172.16.2.1
     nameservers:
       addresses: [ 8.8.8.8, 8.8.4.4, 1.1.1.1 ]
     # Static Route If you need
     routes:
       - to: 172.16.255.1/32
         via: 172.16.2.1
         metric: 0

Static IPv4/IPv6 configuration(dual stack)

/etc/netplan/01-netcfg.yaml
# This file describes the network interfaces available on your system
# For more information, see netplan(5).
network:
  version: 2
  renderer: networkd
  ethernets:
    eno2:
      addresses: [10.0.4.192/24, '2001:db8:1:2::192/64']
      gateway4: 10.0.4.1
      gateway6: 'fe80::1234:56ff:fe78:9abc'
      nameservers:
        addresses: [8.8.8.8, 8.8.4.4, '2001:db8:11:22::53', '2001:db8:33:44::53']

Bridge configuration

/etc/netplan/01-netcfg.yaml
# This file describes the network interfaces available on your system
# For more information, see netplan(5).
network:
  version: 2
  renderer: networkd
  ethernets:
    eno2:
      dhcp4: no
      dhcp6: no
  bridges:
    br0:
      interfaces: [ eno2 ]
      dhcp4: no
      dhcp6: no
      parameters:
        stp: false
      addresses: [ 10.0.4.193/24, '2001:db8:1:2::193/64' ]
      gateway4: 10.0.4.1
      gateway6: 'fe80::1234:56ff:fe78:9abc'
      nameservers:
        addresses: [ 8.8.8.8, 8.8.4.4, '2001:db8:11:22::53', '2001:db8:33:44::53' ]

WIP: Bridge and VLAN configuration

/etc/netplan/01-network-manager-all.yaml
# Let NetworkManager manage all devices on this system
network:
  version: 2
  renderer: NetworkManager
  ethernets:
    enp0s25:
      dhcp4: no
      dhcp6: no
    enp3s0:
      dhcp4: no
      dhcp6: no
#      addresses: [10.0.8.192/22]
#      auth:
#        key-management: 802.1x
#        method: peap
#        identity: wnoguchi
#        password: kotoneaishiteru
#  vlans:
#    vlan4:
#      id: 4
#      link: enp0s25
#    vlan16:
#      id: 16
#      link: enp0s25
#      addresses: [10.0.16.192/22]
  bridges:
    br-home:
      interfaces: [ enp0s25 ]
      dhcp4: no
      dhcp6: no
      parameters:
        stp: false
      addresses: [10.0.4.192/24, '2001:db8:1:2::192/64']
      gateway4: 10.0.4.1
      gateway6: 'fe80::1234:56ff:fe78:9abc'
      nameservers:
        addresses: [8.8.8.8, 8.8.4.4, '2001:db8:11:22::53', '2001:db8:33:44::53']
#  bridges:
#    br-home:
#      interfaces: [ vlan4 ]
#      dhcp4: no
#      dhcp6: no
#      parameters:
#        stp: false
#      addresses: [10.0.4.192/24, '2001:db8:1:2::192/64']
#      gateway4: 10.0.4.1
#      gateway6: 'fe80::1234:56ff:fe78:9abc'
#      nameservers:
#        addresses: [8.8.8.8, 8.8.4.4, '2001:db8:11:22::53', '2001:db8:33:44::53']

WIP: IEEE802.1X configuration

/etc/netplan/01-network-manager-all.yaml
# Let NetworkManager manage all devices on this system
network:
  version: 2
  renderer: NetworkManager
  ethernets:
    enp0s25:
      dhcp4: no
      dhcp6: no
    enp3s0:
      dhcp4: no
      dhcp6: no
#      addresses: [10.0.8.192/22]
#      auth:
#        key-management: 802.1x
#        method: peap
#        identity: wnoguchi
#        password: kotoneaishiteru
#  vlans:
#    vlan4:
#      id: 4
#      link: enp0s25
#    vlan16:
#      id: 16
#      link: enp0s25
#      addresses: [10.0.16.192/22]
  bridges:
    br-home:
      interfaces: [ enp0s25 ]
      dhcp4: no
      dhcp6: no
      parameters:
        stp: false
      addresses: [10.0.4.192/24, '2001:db8:1:2::192/64']
      gateway4: 10.0.4.1
      gateway6: 'fe80::1234:56ff:fe78:9abc'
      nameservers:
        addresses: [8.8.8.8, 8.8.4.4, '2001:db8:11:22::53', '2001:db8:33:44::53']
#  bridges:
#    br-home:
#      interfaces: [ vlan4 ]
#      dhcp4: no
#      dhcp6: no
#      parameters:
#        stp: false
#      addresses: [10.0.4.192/24, '2001:db8:1:2::192/64']
#      gateway4: 10.0.4.1
#      gateway6: 'fe80::1234:56ff:fe78:9abc'
#      nameservers:
#        addresses: [8.8.8.8, 8.8.4.4, '2001:db8:11:22::53', '2001:db8:33:44::53']

References

tech/server/linux/ubuntu/networking/netplan/netplan.txt · Last modified: 2019/08/13 20:34 by wnoguchi