Netplan and how to cook it properly

Ubuntu is an awesome operating system, it has not worked with the Ubuntu server for a long time and there was no point in updating its Desktop from a stable version. And not long ago I had to come across a fresh release of Ubuntu server 18.04, my surprise knew no bounds when I realized that I was inferior to life and could not configure the network because the old kind system for configuring network interfaces using the / etc / network file editing tools / interfaces is gone. But what replaced her? something terrible and at first glance completely incomprehensible, meet Netplan.

Frankly, at first I couldn’t understand what was the matter and “why it was necessary, because everything was so convenient,” but after I got a little practice I realized that it has its own charm. to configure the network in Ubuntu, at least “in other distributions I haven’t seen anything like this.” The significant difference between Netplan is that the configuration is written in YAML , yes you heard right about YAML, the developers decided to keep up with the times (and how much they didn’t extol it, but I still consider it a terrible language.) The main minus of this language is that it is very sensitive to spaces, let’s take a look at the config as an example: the

configuration files are located on the path /etc/netplan/file.yaml, between each block when there should be + 2 spaces.

1) The standard header looks like this:

network:
  version: 2
  renderer: networkd
  ethernets:
    enp3s0f0:
      dhcp4:no

Let's look at what we just did:

  • network: is the start of configuration block.
  • renderer: networkd - here we indicate the network manager that we will use, it is either networkd or NetworkManager
  • version: 2 - here, as I understand it, the YAML version.
  • ethernets: - this block says that we will configure the ethernet protocol.
  • enps0f0: - indicate which network adapter we will configure.
  • dhcp4: no - disable DHCP v4, for 6 v6 dhcp6, respectively

2) Let's try to assign ip addresses:

    enp3s0f0:
      dhcp4:no
      macaddress: bb:11:13:ab:ff:32
      addresses: [10.10.10.2/24, 10.10.10.3/24]
      gateway4: 10.10.10.1
      nameservers:
        addresses: 8.8.8.8

Here we set the poppy, ipv4, gateway and dns server. Note that if we need more than one ip address, we write them separated by commas with a mandatory space after.

3) What if we need bonding ?

  bonds:
    bond0:
      dhcp4: no
      interfaces: [enp3s0f0, enp3s0f1]
      parameters: 
        mode: 802.3ad
        mii-monitor-interval: 1

  • bonds: - a block explaining that we will configure bonding.
  • bond0: - an arbitrary interface name.
  • interfaces: - a set of interfaces collected in bond-ding, '' as previously stated if several parameters are described in square brackets ".
  • parameters: - describe the parameter settings block
  • mode: - indicate the mode by which bonding will work.
  • mii-monitor-interval: - set the monitoring interval to 1 second.

Inside a block named bond, you can also configure parameters such as addresses, gateway4, routes, etc.

We have added redundancy for our network, now it remains only to hang vlan and the configuration can be considered complete.

vlans: 
    vlan10:
      id: 10
      link: bond0
      dhcp4: no
      addresses: [10.10.10.2/24]
      gateway: 10.10.10.1
      routes:
        - to: 10.10.10.2/24
          via: 10.10.10.1
          on-link: true

  • vlans: - declare the vlan configuration block.
  • vlan10: - any name of the vlan interface.
  • id: - the tag of our vlan.
  • link: - the interface through which vlan will be available.
  • routes: - we declare the route description block.
  • - to: - set the address / subnet to which the route is needed.
  • via: - specify the gateway through which our subnet will be available.
  • on-link: - indicate that it is always necessary to register routes when raising the link.

Pay attention to how I put spaces, in YAML it is very important.

Here we described network interfaces, created bonding, and even added vlan-s. Let's apply our config, the netplan apply command will check our config for errors and apply it if successful. Next, the config will itself rise when the system reboots.

Having collected all the previous blocks of code, here's what we got:

network:
  version: 2
  renderer: networkd
  ethernets:
    enp3s0f0:
      dhcp4: no
    ensp3s0f1:
      dhcp4: no
  bonds:
    bond0:
      dhcp4: no
      interfaces: [enp3s0f0, enp3s0f1]
      parameters: 
        mode: 802.3ad
        mii-monitor-interval: 1
  vlan10:
      id: 10
      link: bond0
      dhcp4: no
      addresses: [10.10.10.2/24]
      routes:
        - to: 10.10.10.2/24
          via: 10.10.10.1
          on-link: true
  vlan20:
    id: 20
    link: bond0
    dhcp4: no
    addresses: [10.10.11.2/24]
    gateway: 10.10.11.1
    nameserver:
      addresses: [8.8.8.8]
    

So our network is ready for operation, everything turned out not to be as scary as it seemed at the beginning and the code turned out to be very beautiful and readable. PC thanks for the netplan there is an excellent manual at https://netplan.io/ .

Also popular now: