Ubuntu is an amazing operating system. I hadn't worked with Ubuntu Server for a while, and updating my Desktop from a stable version didn’t make sense. Recently, I had to confront the new release of Ubuntu Server 18.04, and I was astonished to realize how out of touch I had become, unable to configure the network since the old reliable method of configuring network interfaces by editing the /etc/network/interfaces file has become obsolete. So, what replaced it? Something dreadful and, at first glance, completely incomprehensible: meet 'Netplan.'
Honestly, at first, I couldn't understand what the fuss was about and 'why it was necessary' since everything was so convenient before, but after gaining a bit of practice, I realized it has its own charm. So, enough with the lyrical digression, what is Netplan? It’s a new utility for configuring networks in Ubuntu, or at least I haven't seen anything like it in other distributions. A significant distinction of Netplan is that the configuration is written in the , yes, you heard that right, YAML. The developers decided to keep up with the times (and no matter how much it is praised, I still find it to be a terrible language). The main downside of this language is that it is very sensitive to spaces. Let's look at the config for an example.
Configuration files are located at /etc/netplan/filename.yaml, and there should be +2 spaces between each block.
1) The standard header looks like this:
network:
version: 2
renderer: networkd
ethernets:
enp3s0f0:
dhcp4:noLet's review what we just did:
- network: — this is the beginning block of the configuration.
- renderer: networkd — here we specify the network manager we will use, either networkd or NetworkManager.
- version: 2 — this is the version of YAML, as I understand it.
- ethernets: — this block indicates that we will configure the Ethernet protocol.
- enp3s0f0: — we specify which network adapter we will configure.
- dhcp4:no — we disable DHCP v4, for v6 we use dhcp6 accordingly.
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.8Here we defined MAC, IPv4, gateway, and DNS server. Note that if we need more than one IP address, we separate them with commas and include a mandatory space after each.
3) What if we need ?
bonds:
bond0:
dhcp4: no
interfaces: [enp3s0f0, enp3s0f1]
parameters:
mode: 802.3ad
mii-monitor-interval: 1- bonds: — a section explaining that we will configure bonding.
- bond0: — an arbitrary name for the interface.
- interfaces: — a set of interfaces that are gathered into bonding; as mentioned earlier, if there are multiple parameters, we describe them in square brackets.
- parameters: — we describe the configuration block for parameters.
- mode: — we specify the mode in which bonding will operate.
- mii-monitor-interval: — we set the monitoring interval to 1 second.
Inside the block named for the bond, you can also configure parameters such as addresses, gateway4, routes, etc.
We have added redundancy for our network; now we just need to attach the 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: — declaring the configuration block for vlans.
- vlan10: — an arbitrary name for the vlan interface.
- id: — the tag for our vlan.
- link: — the interface through which the vlan will be accessible.
- routes: — declaring the block describing routes.
- — to: — specifying the address/subnet to which the route is needed.
- via: — indicating the gateway through which our subnet will be accessible.
- on-link: — specifying that routes should always be written when bringing up the link.
Note how I space elements; in YAML, this is very important.
Here we have described network interfaces, created bonding, and even added vlans. Let's apply our config; the command netplan apply will check our config for errors and apply it if successful. Subsequently, the config will automatically activate upon system reboot.
Having assembled all the previous blocks of code, here's what we have:
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]
Our network is now ready for operation; it turned out not to be as intimidating as it seemed at first, and the code is very elegant and readable. P.S. Thank you for the excellent manual on netplan at the link provided. .
Source: habr.com
