Ubuntu amazing operating system, haven't worked with it for a long time Ubuntu server, and updating my Desktop from a stable version didn't make sense. And then, not long ago, I had to deal with a brand new release. Ubuntu On server 18.04, I was absolutely amazed when I realized I was way behind the times and couldn't configure my network because the good old system of configuring network interfaces by editing the /etc/network/interfaces file had vanished. And what replaced it? Something terrifying and, at first glance, completely incomprehensible—meet "Netplan."
To be honest, at first I couldn't understand what the deal was and "why it was necessary, after all, everything was so convenient," but after a little practice I realized it had its own charm. So, enough of the lyrical talk, let's continue with what Netplan is. This is a new utility for configuring a network in Ubuntu, at least "I haven't encountered anything like this in other distributions." A significant difference with Netplan is that the configuration is written in the language , yes, you heard right YAML, the developers decided to keep up with the times (and no matter how much they praised it, I still consider it a terrible language). The main disadvantage of this language is that it is very sensitive to spaces, let's look at the config with an example.
The configuration files are located in the /etc/netplan/filename.yaml path, between each block when there should be + 2 spaces.
1) The default header looks like this:
network:
version: 2
renderer: networkd
ethernets:
enp3s0f0:
dhcp4:noLet's take a look at what we've done so far:
- network: is the start block of the configuration.
- renderer: networkd - here we specify the network manager we will use, it is either networkd or NetworkManager
- version: 2 - here, as I understand it, is the YAML version.
- ethernets: - this block says that we will configure the ethernet protocol.
- enps0f0: - specify 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.8Here we set poppy, ipv4, gateway and dns server. Note those that if we need more than one ip address, then we write them separated by commas with a mandatory space after.
3) What if we need ?
bonds:
bond0:
dhcp4: no
interfaces: [enp3s0f0, enp3s0f1]
parameters:
mode: 802.3ad
mii-monitor-interval: 1- bonds: - a block explaining that we will set up bonding.
- bond0: - arbitrary interface name.
- interfaces: - a set of interfaces assembled in bond-ding, "as previously stated, if there are several parameters, we describe them in square brackets".
- parameters: - describe the parameter setting block
- mode: - specify the mode on which bonding will work.
- mii-monitor-interval: - set the monitoring interval to 1 second.
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 up and the setup is 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: - arbitrary name of the vlan interface.
- id: - tag of our vlan.
- link: - interface through which vlan will be available.
- routes: - declare a 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: - specify that routes should always be registered when link is raised.
Pay attention to how I place spaces, in YAML this is very important.
Here we have described network interfaces, created 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 by itself when the system is rebooted.
Having collected all the previous blocks of code, here is 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 it is ready for operation, everything turned out to be not as scary as it seemed at first, and the code turned out to be very beautiful and readable. PC thanks for netplan there is an excellent manual at the link .
Source: habr.com
