📜 ⬆️ ⬇️

Netplan and how to cook it properly

Ubuntu is an amazing operating system, it has not worked with Ubuntu server for a long time and there was no point in updating your Desktop from a stable version. And not long ago I had to deal with the latest release of Ubuntu server 18.04, to my surprise there was no limit when I realized that I was infinitely behind the times and could not configure the network because the good old system for configuring network interfaces using the / etc / network file editing tools / interfaces has sunk into mite. And what came to replace it? 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 getting a little practice I realized that it has its own charm. And so the lyrics are enough to continue what Netplan is a new utility to configure the network in Ubuntu, at least “in other distributions I have not seen anything like it.” The significant difference between Netplan is that the configuration is written in YAML , yes yes you have not misheard YAML, the developers decided to keep up with the times (and however much I didn’t praise him, I still consider it a terrible language). The main minus This language is that it is very sensitive to spaces, let's consider the config using an example.

Configuration files are in the path /etc/netplan/name.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:


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 poppy, ipv4, gateway and dns server. Note that if we need more than one ip address then we write them separated by commas with an obligatory space after.

3) What if we need bonding ?

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


Inside the 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 the 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 


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

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

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] 

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

Source: https://habr.com/ru/post/448400/


All Articles