1
00:00:00,000 --> 00:00:08,600
In this video, we'll talk about persistent network

2
00:00:08,600 --> 00:00:10,160
configuration.

3
00:00:10,160 --> 00:00:12,440
Now, one thing to notice is that persistent network

4
00:00:12,440 --> 00:00:14,160
configuration is different between

5
00:00:14,160 --> 00:00:16,040
the different distributions.

6
00:00:16,040 --> 00:00:18,040
And in this video, we'll talk about the way

7
00:00:18,040 --> 00:00:20,639
how it works on a Red Hat family,

8
00:00:20,639 --> 00:00:24,840
and also about the way how it works on Ubuntu and related.

9
00:00:24,840 --> 00:00:27,120
So NetworkManager is what you use

10
00:00:27,120 --> 00:00:29,200
for persistent interface configuration

11
00:00:29,200 --> 00:00:31,480
on Red Hat family Linux.

12
00:00:31,480 --> 00:00:34,400
And NetworkManager comes with two fantastic front-end

13
00:00:34,400 --> 00:00:38,560
utilities, nmtui, which is a text user interface,

14
00:00:38,560 --> 00:00:42,320
or nmcli, which is a command line interface.

15
00:00:42,320 --> 00:00:44,919
Well, I would recommend you use nmtui

16
00:00:44,919 --> 00:00:49,599
if you want to have an easy interface where you are working

17
00:00:49,599 --> 00:00:52,240
from a menu-driven interface, and you can easily

18
00:00:52,240 --> 00:00:54,880
put in the information that you want to use.

19
00:00:54,880 --> 00:00:58,759
nmcli is very powerful command line utility

20
00:00:58,759 --> 00:01:02,040
where you will create long commands to define exactly what

21
00:01:02,040 --> 00:01:05,040
you want to do in your network.

22
00:01:05,040 --> 00:01:07,160
The configuration that is generated

23
00:01:07,160 --> 00:01:11,400
by either of these utilities is written to etcNetworkManager.

24
00:01:11,400 --> 00:01:14,000
And you could even directly modify the files

25
00:01:14,000 --> 00:01:16,680
that you find in there.

26
00:01:16,680 --> 00:01:20,120
Before continuing, let's have a quick look.

27
00:01:20,120 --> 00:01:22,120
So I'm going to use nmtui.

28
00:01:22,160 --> 00:01:25,199
In nmtui, you need to edit your connection.

29
00:01:25,199 --> 00:01:27,400
You need to select the appropriate connection.

30
00:01:27,400 --> 00:01:29,559
In this case, it's pretty easy because we only

31
00:01:29,559 --> 00:01:31,199
have one of them.

32
00:01:31,199 --> 00:01:34,160
And then you edit.

33
00:01:34,160 --> 00:01:36,519
And in the edit, you are going to enter

34
00:01:36,519 --> 00:01:40,279
the different types of information that you want.

35
00:01:40,279 --> 00:01:43,080
First, make sure that if IP configuration is

36
00:01:43,080 --> 00:01:47,239
set to automatic, that you change that to manual.

37
00:01:47,239 --> 00:01:50,639
And then you enter the manual configuration.

38
00:01:50,720 --> 00:01:52,959
The minimal configuration required

39
00:01:52,959 --> 00:01:56,400
consists of an IP address, a gateway, a DNS server.

40
00:01:56,400 --> 00:01:58,360
And once you are done with that, ensure

41
00:01:58,360 --> 00:02:00,120
that automatically connect is on.

42
00:02:00,120 --> 00:02:02,639
Sometimes in virtual environments,

43
00:02:02,639 --> 00:02:04,120
it defaults to off.

44
00:02:04,120 --> 00:02:06,919
And then you select OK.

45
00:02:06,919 --> 00:02:09,039
That will write the configuration.

46
00:02:09,039 --> 00:02:11,720
Now in Linux, writing the configuration normally

47
00:02:11,720 --> 00:02:12,720
is not enough.

48
00:02:12,720 --> 00:02:16,399
After writing the configuration, you need to activate it.

49
00:02:16,399 --> 00:02:18,559
And that is something that nmtui allows

50
00:02:18,559 --> 00:02:20,600
you to do in an easy way as well.

51
00:02:20,600 --> 00:02:22,960
So you use activate the connection.

52
00:02:22,960 --> 00:02:24,759
And there you see your connection.

53
00:02:24,759 --> 00:02:27,199
You press Enter to deactivate.

54
00:02:27,199 --> 00:02:29,080
You press Enter to activate.

55
00:02:29,080 --> 00:02:31,720
And now the connection has picked it up.

56
00:02:31,720 --> 00:02:36,679
So you can use quit to verify that it worked out all right.

57
00:02:36,679 --> 00:02:39,399
Well, here we can see in the IPA output

58
00:02:39,399 --> 00:02:41,479
that the IP address that I configured

59
00:02:41,479 --> 00:02:43,160
is indeed operational.

60
00:02:43,160 --> 00:02:46,600
You can also go to ETC network manager.

61
00:02:46,600 --> 00:02:49,600
In there, you will find the system connections.

62
00:02:49,600 --> 00:02:52,080
And in the system connections, you

63
00:02:52,080 --> 00:02:54,679
have a configuration file that contains

64
00:02:54,679 --> 00:02:58,759
the exact configuration that was just added,

65
00:02:58,759 --> 00:03:00,880
as you can see right here.

66
00:03:00,880 --> 00:03:02,960
Now on Ubuntu, NetPlan is what you

67
00:03:02,960 --> 00:03:06,360
use for persistent interface configuration.

68
00:03:06,360 --> 00:03:09,839
And NetPlan is using systemd networkd,

69
00:03:09,839 --> 00:03:12,919
which is a part of the systemd manager of everything,

70
00:03:12,919 --> 00:03:15,800
on Ubuntu server as the back end.

71
00:03:15,800 --> 00:03:18,759
And on Ubuntu workstation, network manager

72
00:03:18,759 --> 00:03:20,440
is used as the back end.

73
00:03:20,440 --> 00:03:22,000
That's kind of funny.

74
00:03:22,000 --> 00:03:24,720
But systemd networkd is used on Ubuntu server

75
00:03:24,720 --> 00:03:28,479
because Ubuntu thinks that's a better solution for service.

76
00:03:28,479 --> 00:03:32,960
And network manager is stronger in handling Wi-Fi connections.

77
00:03:32,960 --> 00:03:35,160
And that is why it's used on a workstation,

78
00:03:35,160 --> 00:03:40,080
to make it easy to swap between different Wi-Fi networks.

79
00:03:40,080 --> 00:03:42,080
So systemd networkd is the standard

80
00:03:42,080 --> 00:03:45,039
for managing networking on Ubuntu server.

81
00:03:45,039 --> 00:03:48,679
And it works with YAML files that are provided by NetPlan.

82
00:03:48,679 --> 00:03:53,320
And you can find them in the etc NetPlan directory.

83
00:03:53,320 --> 00:03:57,279
So in the NetPlan configuration, renderer networkd

84
00:03:57,279 --> 00:04:00,199
is used to connect to systemd networkd.

85
00:04:00,199 --> 00:04:02,199
And the NetPlan configuration files

86
00:04:02,199 --> 00:04:04,759
need to be created manually for persistent network

87
00:04:04,759 --> 00:04:06,279
configuration.

88
00:04:06,279 --> 00:04:09,759
Unfortunately, Ubuntu server doesn't know any utility

89
00:04:09,759 --> 00:04:12,440
to make that easier for you.

90
00:04:12,440 --> 00:04:15,960
There's a front end utility for querying network status, which

91
00:04:15,960 --> 00:04:18,480
is a part of the systemd components.

92
00:04:18,480 --> 00:04:21,000
And that's networkctl.

93
00:04:21,000 --> 00:04:25,000
Systemd likes working with these ctl utilities,

94
00:04:25,000 --> 00:04:29,480
like loginctl, systemctl, networkctl,

95
00:04:29,480 --> 00:04:31,480
and there's more of them.

96
00:04:31,480 --> 00:04:35,079
So networkctl status and networkctl up and down

97
00:04:35,079 --> 00:04:39,640
are telling systemd networkd to pick up the configuration.

98
00:04:39,640 --> 00:04:43,000
Now let me show you how we can work with this configuration.

99
00:04:43,000 --> 00:04:45,320
I'm going to create a configuration file that

100
00:04:45,320 --> 00:04:49,760
looks very much like this in the etc NetPlan directory.

101
00:04:49,760 --> 00:04:54,399
And then we use sudo netpan apply to apply our networkctl

102
00:04:54,399 --> 00:04:55,720
status.

103
00:04:55,720 --> 00:04:59,239
And then we use sudo netplan apply to activate it

104
00:04:59,239 --> 00:05:03,320
and networkctl status to verify that it all worked out all

105
00:05:03,320 --> 00:05:04,359
right.

106
00:05:04,359 --> 00:05:08,559
Another very convenient command is sudo netplan try.

107
00:05:08,559 --> 00:05:10,720
That allows you to do a dry run.

108
00:05:10,720 --> 00:05:12,600
And in the dry run, you will find

109
00:05:12,600 --> 00:05:14,440
if you made any syntax errors.

110
00:05:14,440 --> 00:05:17,200
It will warn you about it so that you can fix it

111
00:05:17,200 --> 00:05:21,079
before making it permanent.

112
00:05:21,079 --> 00:05:24,839
So let's have a look at the etc NetPlan directory.

113
00:05:24,839 --> 00:05:32,239
So I need sudo vim 99 config to change the configuration.

114
00:05:32,239 --> 00:05:33,119
And what do we see?

115
00:05:33,119 --> 00:05:36,399
Well, we see a configuration file that is almost all right,

116
00:05:36,399 --> 00:05:39,480
but there's a couple of indentation problems.

117
00:05:39,480 --> 00:05:41,480
And let me fix it.

118
00:05:41,480 --> 00:05:43,399
The problem here is that ethernet

119
00:05:43,399 --> 00:05:46,519
needs to be at the same level as version and renderer.

120
00:05:46,519 --> 00:05:49,559
And then as a child element to ethernet,

121
00:05:49,559 --> 00:05:51,839
we have the different network interfaces.

122
00:05:51,839 --> 00:05:54,079
In this case, it's one only.

123
00:05:54,079 --> 00:05:56,320
With the addresses, only one address,

124
00:05:56,320 --> 00:05:58,920
with the gateway, with the name server.

125
00:05:58,920 --> 00:06:01,119
And that should be doing all right.

126
00:06:01,119 --> 00:06:06,119
So sudo netplan try is doing what?

127
00:06:06,119 --> 00:06:11,000
And that is telling me, oh, its permissions are too open.

128
00:06:11,000 --> 00:06:16,079
And there we can see gateway 4 has been deprecated.

129
00:06:16,079 --> 00:06:18,359
Use default routes instead.

130
00:06:18,359 --> 00:06:21,640
And error in network definition expected sequence.

131
00:06:21,640 --> 00:06:23,320
So there's a couple of fixes.

132
00:06:23,320 --> 00:06:26,040
So it's good that we checked what is going on.

133
00:06:26,040 --> 00:06:31,519
So let's get back to the NetPlan configuration file,

134
00:06:31,519 --> 00:06:33,519
where I need to apply a couple of changes.

135
00:06:34,519 --> 00:06:38,279
So addresses, it seems to be picky about the indentation.

136
00:06:38,279 --> 00:06:40,760
So I'm going to indent it a lot more.

137
00:06:40,760 --> 00:06:45,559
And gateway 4, yeah, gateway 4, that is an old way of writing it.

138
00:06:45,559 --> 00:06:47,839
So I'm going to remove that.

139
00:06:47,839 --> 00:06:52,359
And I'm going to replace that with a routes section.

140
00:06:52,359 --> 00:06:57,239
And there we have the routes, where we are going to default.

141
00:06:58,040 --> 00:07:04,239
And via 192.168.29.2.

142
00:07:04,239 --> 00:07:05,559
And then we have name servers.

143
00:07:05,559 --> 00:07:09,559
Well, it's elegant if instead of address is written this way,

144
00:07:09,559 --> 00:07:12,839
we make it a list, because really it's a list argument

145
00:07:12,839 --> 00:07:14,600
for the name servers.

146
00:07:14,600 --> 00:07:16,600
And this should be doing it.

147
00:07:16,600 --> 00:07:20,519
So let's try it again.

148
00:07:20,519 --> 00:07:24,040
Sudo netplan try is going to tell it.

149
00:07:24,040 --> 00:07:26,679
And try is going to tell it.

150
00:07:26,679 --> 00:07:28,720
And then what do we see?

151
00:07:28,720 --> 00:07:33,239
We see the address is missing a slash prefix length.

152
00:07:33,239 --> 00:07:34,320
And is that right?

153
00:07:34,320 --> 00:07:40,720
Well, we have the prefix length specified as a slash 24.

154
00:07:40,720 --> 00:07:42,559
And it doesn't seem to like it.

155
00:07:42,559 --> 00:07:50,399
So let's rewrite it to an old cell prefix and try it again.

156
00:07:50,399 --> 00:07:55,959
OK, let's do sudo netplan try.

157
00:07:55,959 --> 00:07:59,000
And oh boy, there we can see two different things.

158
00:07:59,000 --> 00:08:00,720
Yeah, I forgot about permissions.

159
00:08:00,720 --> 00:08:01,600
That's an easy one.

160
00:08:01,600 --> 00:08:09,519
Sudo chmod 600 on 99config.yaml.

161
00:08:09,519 --> 00:08:16,600
And then back to sudo vim on 99config.yaml.

162
00:08:16,600 --> 00:08:18,519
Now it's a little bit confusing, because it's

163
00:08:18,519 --> 00:08:22,200
complaining about the address is missing the prefix length.

164
00:08:22,200 --> 00:08:24,279
But the problem is really not in the address,

165
00:08:24,279 --> 00:08:26,480
because you can see the prefix.

166
00:08:26,480 --> 00:08:29,160
The problem is a little bit lower.

167
00:08:29,160 --> 00:08:31,359
It's an indentation problem.

168
00:08:31,359 --> 00:08:33,440
And it's in the name servers.

169
00:08:33,440 --> 00:08:36,119
Name servers is not an ethernet.

170
00:08:36,119 --> 00:08:37,719
And the way it's written right now,

171
00:08:37,719 --> 00:08:40,599
it's configuring two ethernet interfaces,

172
00:08:40,599 --> 00:08:43,840
ENS160 as well as name servers.

173
00:08:43,840 --> 00:08:47,400
Name servers is a property of the ethernets.

174
00:08:47,400 --> 00:08:49,320
So let's put it this way.

175
00:08:49,320 --> 00:08:51,200
And then let's try it again.

176
00:08:51,200 --> 00:08:54,359
And it should be so much better.

177
00:08:54,359 --> 00:08:56,960
And as you can see, it's trying.

178
00:08:56,960 --> 00:08:59,239
It's asking, do you want to keep these settings?

179
00:08:59,239 --> 00:09:02,039
And yeah, I want to keep these settings.

180
00:09:02,039 --> 00:09:04,520
And the configuration is now accepted.

181
00:09:04,520 --> 00:09:07,320
And we have used netplan to change it.

182
00:09:07,320 --> 00:09:12,280
So IPA is showing right here that it has been applied.

183
00:09:12,280 --> 00:09:15,039
And we are all good.

184
00:09:15,039 --> 00:09:20,200
Maybe also funny is networkctl.

185
00:09:20,200 --> 00:09:23,559
So networkctl status is a nice way

186
00:09:23,559 --> 00:09:26,200
to figure out what is currently going on

187
00:09:26,200 --> 00:09:30,640
and to query your network interface from the networkctl

188
00:09:30,640 --> 00:09:32,280
point of view.

189
00:09:32,280 --> 00:09:35,640
After all, networkctl is a part of networkd

190
00:09:35,640 --> 00:09:38,080
that is managing the netplan configuration that

191
00:09:38,080 --> 00:09:40,640
is used behind all of this.

