In this lesson, we'll learn how to bridge and bond network interfaces.
So let's see how we can do that with Netplan and Ubuntu
to get started. We can take a look at some example files. First,
we'll see that there's an example
YAML configuration file for just about any network setup we want.
But in this case, bridge dot YAMLS seems to be what we're looking for.
Let's display its contents
here. We can see it's a rather straightforward configuration.
I'll explain the important lines once we edit and adapt this file for our own needs.
Before that let's copy this file to the Netplan configuration directory,
we'll basically use the file as a template that
we can build upon to make our life easier
and to avoid error messages,
we'll change the permissions of this file.
So it's a bit more secure.
Before we edit this file,
we need to know the name of the network interfaces we'll use in our config.
So let's run IP
C link
to list our interfaces.
Now ENP 0 S3 here is our main interface.
We won't touch that since changing network settings
on it might break our current SSH connection.
But we can freely use the other two interfaces
and they are down. So they're currently not used for anything.
But let's make a mental note that the names of
the interfaces will bridge together are ENP zero S eight
and ENP zero S nine.
Now let's edit our Netplan YAML file.
We can see that this definition of a network bridge lists a single interface,
but we'll want to bridge two of them ENP zero S eight
and ENP zero S nine that we have on our system.
Now, the Ethernet section lists Ethernet devices.
It's how we inform Netplan that ENP three S zero is actually an Ethernet device.
Otherwise it would not know its type and it would not know how to deal with it.
So let's change ENP three S zero to the actual name
of our first interface which is ENP zero S eight.
Then we'll add the other interface in this list under the Ethernet's definitions.
Remember we have to respect proper indentation,
but we can just model it after the two lines above.
So we'll add ENP zero S nine
and DH DP four equals no
to include our ENP zero S nine device. Here.
In this case, we disable
DHCP auto configuration for the individual
Ethernet devices,
but we enabled the HCP auto configuration for the bridge itself.
So ENP zero S eight and ENP zero S nine won't get
an IP address but the bridge that glues them together will,
it's not mandatory to do it this way though, in the real world,
there can be many variations to the setup.
The bridges line begins the definition for our network bridges.
Next BR Z zero is simply the name we pick for our bridge.
We can freely choose any name we want. If we replace this text.
On the next lines, we follow up with the parameters of this bridge.
First,
we say that we do want this bridge to auto configure IP D
four settings for itself by asking for this data from a DHCP server.
Next, we follow up with the interfaces that we want to add to this bridge.
So we'll modify ENP three S zero with the name of the first interface.
We want to use ENP zero S eight
and we'll add our second interface to this bridge E and P zero S nine.
This config is now ready to be deployed.
So let's save our file and try it out
and will press enter.
If we inspect our network interfaces again with IP dash C link,
we'll notice a couple of differences
E and P zero S eight and ENP zero S nine are now in an upstate.
So they're active and processing network connections.
Also notice this text, both interfaces mention master BR zero,
which immediately tells us that these interfaces belong to
the BR zero bridge and are slaves to it.
Since BR zero is the master.
Also note that BR zero now appears listed as an extra interface in this list.
So it looks like our Netplan config did its job.
However, we also told Netplan to use DHCP auto configuration for this bridge.
So let's check our IP settings
and we can now see that our bridge does in fact have an IPV four address.
So
DHCP auto configuration worked out too.
In fact, many other IPv4 settings were configured as well.
Now, if we take a look at network routes,
we'll see that even routes were configured for this bridge.
Now let's free up our two network interfaces so that we can
also test how we can add them to a network bond.
First, we remove the bridge definition from Netplan by deleting the AML file
and then we can simply delete the bridge interface to free up our slave devices.
In a real scenario,
it would be better to just reboot the server to
make sure that all previous network settings are reset.
But for our experimental purposes, this will be enough.
Now, let's reapply the same procedure. When bonding our network interfaces
first, we'll copy the example config file for a network bond definition
and then we'll change the permissions
and then let's edit this file,
Etsy Netplan
99 dash bond dot YAML.
And we need to change our Ethernet.
Unfortunately, this file is missing a few important lines.
If we tried to apply this config with Netplan,
it would throw some errors saying that some network interfaces are not defined
more specifically what we have under the interfaces line,
which makes sense.
It does not know what type of interfaces these are
to fix this, we can add these lines under the renderer.
So we simply tell that plan that the interfaces we'll mention later in the config
E and P zero S eight and ENP zero S nine are Ethernet devices.
Basically wired network cards.
It's worth mentioning that in a real scenario, these interfaces might be defined as
Ethernet type devices in an entirely different YAML file.
There might be a dedicated file defining Ethernet devices
and a different file defining the network bond.
So this Ethernet's list might simply be included somewhere else.
Keep that in mind when exploring and editing Netplan configuration files.
Now let's continue
the bonds line instructs Netplan that will define bonds in here.
Next, we pick bond zero as the name for this network bonding interface.
Again, we can choose any name we want.
Then we follow up with enabling
DHCP four auto configuration
and we list the network interfaces we want to add to this bond.
So here we have it defined as ENP zero S eight
and E MP zero S nine.
Finally, we define parameters for this network bond
and probably the most important parameter is the bond mode.
In our previous theoretical lesson about bridges and bonds,
we learned about various modes that bonds support
the values we can use here are
balancer R to use round robin or mode zero,
active backup to use the active slash backup mode, one
balance X or to use the X or mode two
broadcast for mode 3802.3 ad for the I triple E 802.3 ad mode four
balance tlb for the adaptive transmit load balancing mode or mode five
or balance A lb for the adaptive load balancing mode six,
I'll show you how to find these possible values in the manual.
But in our case,
let's stick with the previously defined active dash backup mode here
because unlike some of the other modes,
we can see this mode requires an extra parameter,
namely what the primary or active interface should be by default.
So let's modify this line to make ENP zero S eight our primary interface in this bond.
And now let's save the file
to get a refresh on the values. Netplan accepts as valid bonding modes.
We can open up the manual
by typing in man Netplan
in search for the text bonding.
OK. And if we skip to the third result, we'll see this
which shows us the possible values that I mentioned before.
Also quite useful, we can see other parameters to use for a bonding interface.
But for now let's apply our Netplan config
and we'll notice a difference here.
Netplan tells us that we can't use the try command because reverting
or undoing changes is not supported in case something goes wrong.
So we simply need to make sure our config
is correct and hope we don't break our connection
on a real setup.
You should make sure you have a way to fix this if SSH won't work anymore.
All right. So we can only use the apply command to activate or define network bond.
So let's do that.
Now, if we check the IP settings again,
we'll see that the bond was created and an IP address was autoconfigured.
Also,
we can spot the text master Bond zero next to our two interfaces which just like we
saw with bridges signals that these two interfaces
belong to the bonding interface called bond zero.
And we also have an option to see additional details about a bond.
We can just explore the contents in the special directory slash proc
slash net slash bonding followed by the name of the bond in
this case bond zero.
Now, if we list network interfaces again,
we see this.
Now here's the interesting thing Bond zero is listed just
like any other network interface along our Ethernet devices above.
So far as Linux is concerned,
even if a bridge or bond is a bit more special than a regular Ethernet device,
it's still treated the same way in some regards,
which means we can use commands like this
or commands like this,
the same commands we can use on regular Ethernet interfaces,
we can also use on bridge or bond interfaces.
So we can add, remove change IP settings on the fly.
The same way we did in our lesson about
configuring IPV four and IPV six network settings.
Just remember that changes made with the IP command
are temporary and they'll be lost after a reboot.
So thank you for watching this lesson and I'll see you in the next one.