In this video, we'll talk about persistent network
configuration.
Now, one thing to notice is that persistent network
configuration is different between
the different distributions.
And in this video, we'll talk about the way
how it works on a Red Hat family,
and also about the way how it works on Ubuntu and related.
So NetworkManager is what you use
for persistent interface configuration
on Red Hat family Linux.
And NetworkManager comes with two fantastic front-end
utilities, nmtui, which is a text user interface,
or nmcli, which is a command line interface.
Well, I would recommend you use nmtui
if you want to have an easy interface where you are working
from a menu-driven interface, and you can easily
put in the information that you want to use.
nmcli is very powerful command line utility
where you will create long commands to define exactly what
you want to do in your network.
The configuration that is generated
by either of these utilities is written to etcNetworkManager.
And you could even directly modify the files
that you find in there.
Before continuing, let's have a quick look.
So I'm going to use nmtui.
In nmtui, you need to edit your connection.
You need to select the appropriate connection.
In this case, it's pretty easy because we only
have one of them.
And then you edit.
And in the edit, you are going to enter
the different types of information that you want.
First, make sure that if IP configuration is
set to automatic, that you change that to manual.
And then you enter the manual configuration.
The minimal configuration required
consists of an IP address, a gateway, a DNS server.
And once you are done with that, ensure
that automatically connect is on.
Sometimes in virtual environments,
it defaults to off.
And then you select OK.
That will write the configuration.
Now in Linux, writing the configuration normally
is not enough.
After writing the configuration, you need to activate it.
And that is something that nmtui allows
you to do in an easy way as well.
So you use activate the connection.
And there you see your connection.
You press Enter to deactivate.
You press Enter to activate.
And now the connection has picked it up.
So you can use quit to verify that it worked out all right.
Well, here we can see in the IPA output
that the IP address that I configured
is indeed operational.
You can also go to ETC network manager.
In there, you will find the system connections.
And in the system connections, you
have a configuration file that contains
the exact configuration that was just added,
as you can see right here.
Now on Ubuntu, NetPlan is what you
use for persistent interface configuration.
And NetPlan is using systemd networkd,
which is a part of the systemd manager of everything,
on Ubuntu server as the back end.
And on Ubuntu workstation, network manager
is used as the back end.
That's kind of funny.
But systemd networkd is used on Ubuntu server
because Ubuntu thinks that's a better solution for service.
And network manager is stronger in handling Wi-Fi connections.
And that is why it's used on a workstation,
to make it easy to swap between different Wi-Fi networks.
So systemd networkd is the standard
for managing networking on Ubuntu server.
And it works with YAML files that are provided by NetPlan.
And you can find them in the etc NetPlan directory.
So in the NetPlan configuration, renderer networkd
is used to connect to systemd networkd.
And the NetPlan configuration files
need to be created manually for persistent network
configuration.
Unfortunately, Ubuntu server doesn't know any utility
to make that easier for you.
There's a front end utility for querying network status, which
is a part of the systemd components.
And that's networkctl.
Systemd likes working with these ctl utilities,
like loginctl, systemctl, networkctl,
and there's more of them.
So networkctl status and networkctl up and down
are telling systemd networkd to pick up the configuration.
Now let me show you how we can work with this configuration.
I'm going to create a configuration file that
looks very much like this in the etc NetPlan directory.
And then we use sudo netpan apply to apply our networkctl
status.
And then we use sudo netplan apply to activate it
and networkctl status to verify that it all worked out all
right.
Another very convenient command is sudo netplan try.
That allows you to do a dry run.
And in the dry run, you will find
if you made any syntax errors.
It will warn you about it so that you can fix it
before making it permanent.
So let's have a look at the etc NetPlan directory.
So I need sudo vim 99 config to change the configuration.
And what do we see?
Well, we see a configuration file that is almost all right,
but there's a couple of indentation problems.
And let me fix it.
The problem here is that ethernet
needs to be at the same level as version and renderer.
And then as a child element to ethernet,
we have the different network interfaces.
In this case, it's one only.
With the addresses, only one address,
with the gateway, with the name server.
And that should be doing all right.
So sudo netplan try is doing what?
And that is telling me, oh, its permissions are too open.
And there we can see gateway 4 has been deprecated.
Use default routes instead.
And error in network definition expected sequence.
So there's a couple of fixes.
So it's good that we checked what is going on.
So let's get back to the NetPlan configuration file,
where I need to apply a couple of changes.
So addresses, it seems to be picky about the indentation.
So I'm going to indent it a lot more.
And gateway 4, yeah, gateway 4, that is an old way of writing it.
So I'm going to remove that.
And I'm going to replace that with a routes section.
And there we have the routes, where we are going to default.
And via 192.168.29.2.
And then we have name servers.
Well, it's elegant if instead of address is written this way,
we make it a list, because really it's a list argument
for the name servers.
And this should be doing it.
So let's try it again.
Sudo netplan try is going to tell it.
And try is going to tell it.
And then what do we see?
We see the address is missing a slash prefix length.
And is that right?
Well, we have the prefix length specified as a slash 24.
And it doesn't seem to like it.
So let's rewrite it to an old cell prefix and try it again.
OK, let's do sudo netplan try.
And oh boy, there we can see two different things.
Yeah, I forgot about permissions.
That's an easy one.
Sudo chmod 600 on 99config.yaml.
And then back to sudo vim on 99config.yaml.
Now it's a little bit confusing, because it's
complaining about the address is missing the prefix length.
But the problem is really not in the address,
because you can see the prefix.
The problem is a little bit lower.
It's an indentation problem.
And it's in the name servers.
Name servers is not an ethernet.
And the way it's written right now,
it's configuring two ethernet interfaces,
ENS160 as well as name servers.
Name servers is a property of the ethernets.
So let's put it this way.
And then let's try it again.
And it should be so much better.
And as you can see, it's trying.
It's asking, do you want to keep these settings?
And yeah, I want to keep these settings.
And the configuration is now accepted.
And we have used netplan to change it.
So IPA is showing right here that it has been applied.
And we are all good.
Maybe also funny is networkctl.
So networkctl status is a nice way
to figure out what is currently going on
and to query your network interface from the networkctl
point of view.
After all, networkctl is a part of networkd
that is managing the netplan configuration that
is used behind all of this.