WEBVTT - This file was automatically generated by VIMEO

0
00:00:07.100 --> 00:00:10.300
In this video, we will look at networking inside our ec2 Linux

1
00:00:10.300 --> 00:00:10.700
 instance.

2
00:00:12.400 --> 00:00:15.200
Our plan is to explore how Linux handles network interfaces in

3
00:00:15.200 --> 00:00:18.100
 network connections. The first thing you'll do is learn how

4
00:00:18.100 --> 00:00:20.500
 network interfaces are brought up using system d

5
00:00:21.400 --> 00:00:24.500
You learn about the IP Command this command is a Swiss army

6
00:00:24.500 --> 00:00:27.900
 knife and you can use it for managing network interfaces and routes. You

7
00:00:27.900 --> 00:00:30.300
 also use the socket statistics command to view

8
00:00:30.300 --> 00:00:33.500
 open ports and active connections on the host. Let's get

9
00:00:33.500 --> 00:00:36.400
 started. Okay, so back in the terminal once again.

10
00:00:37.500 --> 00:00:40.800
So networking Linux can be complicated as we

11
00:00:40.800 --> 00:00:43.200
 learned earlier in this course AWS takes care of a lot

12
00:00:43.200 --> 00:00:46.500
 of the network stacked for us. However, this is some cut.

13
00:00:46.500 --> 00:00:49.400
 However, there's some basic information to commands. You

14
00:00:49.400 --> 00:00:52.200
 should know that allow you to probe and troubleshoot your

15
00:00:52.200 --> 00:00:56.100
 network. Let's start from the beginning when a Lennox host boots networking

16
00:00:55.100 --> 00:00:58.100
 is one of the earliest tasks that are actually started.

17
00:00:58.800 --> 00:01:02.400
We could see this using the system control command. We'll

18
00:01:01.400 --> 00:01:05.100
 explore systemd system CTL or

19
00:01:04.100 --> 00:01:07.500
 control in another video. But for

20
00:01:07.500 --> 00:01:10.200
 now, we're just gonna use it so you can see how the network has started on your

21
00:01:10.200 --> 00:01:12.000
 Linux hose. So in your terminal

22
00:01:12.700 --> 00:01:15.200
type the command system CTL

23
00:01:16.400 --> 00:01:18.800
status and then Network

24
00:01:21.400 --> 00:01:24.500
Service, so we want to get the status of a

25
00:01:24.500 --> 00:01:27.700
 network service unit inside system

26
00:01:27.700 --> 00:01:29.600
 d That's this basically what this command reads?

27
00:01:30.600 --> 00:01:33.200
Okay. So the first thing that you jump out to you right now

28
00:01:33.200 --> 00:01:36.100
 is that this unit is loaded.

29
00:01:37.100 --> 00:01:40.300
And it's active and running. And so that means our network is

30
00:01:40.300 --> 00:01:43.200
 up and running if it was not enabled or

31
00:01:43.200 --> 00:01:46.200
 not running. Obviously, we would have been able to SSH into this.

32
00:01:46.200 --> 00:01:49.900
 Okay, so you can see here. This exec Stark

33
00:01:49.900 --> 00:01:52.300
 is is a system D which tells us

34
00:01:52.300 --> 00:01:54.800
 to what command to run to start this unit.

35
00:01:55.700 --> 00:01:58.500
You can see there's a script here called Network and it's located

36
00:01:58.500 --> 00:02:01.300
 inside the initialize or

37
00:02:01.300 --> 00:02:04.200
 init.d directory and we passed the

38
00:02:04.200 --> 00:02:05.100
 start command to it.

39
00:02:05.800 --> 00:02:08.700
The next thing you should look at right here is in that

40
00:02:08.700 --> 00:02:10.700
 inside this network service.

41
00:02:11.600 --> 00:02:14.200
This other command got fired got it

42
00:02:14.200 --> 00:02:17.500
 executed and this is DHC client and what this

43
00:02:17.500 --> 00:02:20.600
 is what this does is this goes out if you're unfamiliar with

44
00:02:20.600 --> 00:02:23.300
 DHCP. This will go out and get us an

45
00:02:23.300 --> 00:02:26.300
 IP address for our particular interface. And in

46
00:02:26.300 --> 00:02:29.100
 our case when we created our subnet we told it to give

47
00:02:29.100 --> 00:02:32.300
 out an IP address if it wanted one and so here

48
00:02:32.300 --> 00:02:33.100
 you could see that.

49
00:02:34.200 --> 00:02:37.600
We do an et80 least and that's an Ethernet

50
00:02:37.600 --> 00:02:38.800
 0 lease.

51
00:02:39.400 --> 00:02:42.700
And you can see here that the IP comes back the host

52
00:02:42.700 --> 00:02:45.400
 comes back on this and this will make more sense in

53
00:02:45.400 --> 00:02:48.200
 a second. But I want to do to see that this network gets started

54
00:02:48.200 --> 00:02:51.000
 system D actually starts our Network for us

55
00:02:51.100 --> 00:02:54.300
 and then it actually creates the interfaces if we

56
00:02:54.300 --> 00:02:57.300
 wanted to we could go ahead and take a look at the script really

57
00:02:57.300 --> 00:02:57.600
 fast.

58
00:02:58.800 --> 00:03:01.300
I won't go into too much into it, but I want you to see

59
00:03:01.300 --> 00:03:04.800
 kind of how these network interfaces are created.

60
00:03:05.600 --> 00:03:08.300
So I'm just gonna use the Vim editor. Obviously if

61
00:03:08.300 --> 00:03:12.100
 you use Nano or something else in the Box, you totally can so we'll

62
00:03:11.100 --> 00:03:12.900
 start here at the top.

63
00:03:13.900 --> 00:03:16.100
And basically the script just tells you that it brings up

64
00:03:16.100 --> 00:03:17.000
 and down networking.

65
00:03:17.700 --> 00:03:21.200
And there's a whole bunch of checking here it

66
00:03:20.200 --> 00:03:23.600
 checks for this place called

67
00:03:23.600 --> 00:03:26.500
 Sisk of fig Network scripts inside. This these scripts.

68
00:03:26.500 --> 00:03:30.200
 There's a script for each of your your interfaces physical interfaces

69
00:03:29.200 --> 00:03:32.800
 that you want to bring up in Virtual as well and basically

70
00:03:32.800 --> 00:03:35.300
 just goes through and it brings up all

71
00:03:35.300 --> 00:03:38.600
 your connections. You can tell your uses the networking manager

72
00:03:38.600 --> 00:03:41.500
 CLI, if if it's enabled and this

73
00:03:41.500 --> 00:03:44.300
 vlans that bring up so this script feel free to take a

74
00:03:44.300 --> 00:03:47.300
 peek through it. It's it's a little bit long and there's a lot of stuff going on

75
00:03:47.300 --> 00:03:50.600
 here. But just to just the big takeaway here. Is that

76
00:03:50.600 --> 00:03:53.300
 system D starts a networking these interfaces come

77
00:03:53.300 --> 00:03:56.500
 up and they connect to whatever networks that were configure them

78
00:03:56.500 --> 00:03:56.600
 to

79
00:03:57.100 --> 00:03:57.400
Okay.

80
00:03:58.100 --> 00:03:59.000
so if we wanted to

81
00:04:00.200 --> 00:04:03.100
we wanted to see the interfaces that are actually on your Linux hose.

82
00:04:03.100 --> 00:04:06.100
 There's a there's a command that we could use and in fact

83
00:04:06.100 --> 00:04:09.200
 this command like I said in the intro is the Swiss armina. This command

84
00:04:09.200 --> 00:04:12.300
 does a little bit of everything it could bring interfaces up and down. You can

85
00:04:12.300 --> 00:04:15.600
 create a new interface you can set routes. So there's

86
00:04:15.600 --> 00:04:18.200
 a lot going on. So we're gonna focus on just a few of the

87
00:04:18.200 --> 00:04:22.000
 commands here just so you can troubleshoot or or Identify

88
00:04:21.500 --> 00:04:24.500
 some some possible issues or just the

89
00:04:24.500 --> 00:04:27.800
 actual devices network devices on your host. Okay.

90
00:04:27.800 --> 00:04:30.300
 So we're gonna use the IP Command. So you're gonna

91
00:04:30.300 --> 00:04:34.200
 type IP and we're gonna use the add our

92
00:04:33.200 --> 00:04:36.700
 sub command which is short for address and

93
00:04:36.700 --> 00:04:39.300
 then list so iPad or list and this

94
00:04:39.300 --> 00:04:42.500
 should show all the interfaces that we have on our on our

95
00:04:42.500 --> 00:04:42.600
 host.

96
00:04:43.400 --> 00:04:46.600
All right. So as you can see here, there are two interfaces

97
00:04:46.600 --> 00:04:49.600
 and you can see the first one is this l or loopback

98
00:04:49.600 --> 00:04:52.800
 which is an internal interface that services and

99
00:04:52.800 --> 00:04:55.100
 other stuff can use that does not the network packets. Don't

100
00:04:55.100 --> 00:04:58.300
 leave your host and this is llo which is

101
00:04:58.300 --> 00:05:04.000
 your loopback and as you can tell here the IP address is 127.0.01

102
00:05:01.000 --> 00:05:04.300
 or

103
00:05:04.300 --> 00:05:06.700
 Local Host you may have as well as known as

104
00:05:07.300 --> 00:05:10.500
Their second interface is what we saw earlier for that DHC

105
00:05:10.500 --> 00:05:11.800
 client, which is et80.

106
00:05:12.900 --> 00:05:15.400
And so as you can see this has an IP address

107
00:05:15.400 --> 00:05:18.600
 of 10.0.1.9 that address should

108
00:05:18.600 --> 00:05:21.300
 look familiar to you. That is because that

109
00:05:21.300 --> 00:05:24.600
 is the range of our subnet that we created

110
00:05:24.600 --> 00:05:28.700
 this host in which was the 10.0.1.0 /

111
00:05:28.700 --> 00:05:31.200
 24. So this is we got ended up

112
00:05:31.200 --> 00:05:33.700
 getting a DOT nine host address.

113
00:05:34.700 --> 00:05:36.700
So with the two addresses there.

114
00:05:37.700 --> 00:05:40.000
And that's it on this host as you can

115
00:05:40.100 --> 00:05:43.700
 see one of them is an internal connection and this one actually connects out

116
00:05:43.700 --> 00:05:46.600
 the eth0 actually connects out

117
00:05:46.600 --> 00:05:49.000
 to our subnet inside our VPC.

118
00:05:50.200 --> 00:05:50.800
You can also.

119
00:05:52.200 --> 00:05:55.500
If you wanted to show just the specific interface and

120
00:05:55.500 --> 00:05:58.200
 not both of them you can use the IP Adder command

121
00:05:58.200 --> 00:05:59.200
 you can show.

122
00:06:00.400 --> 00:06:04.300
The device and in this case, we want et80 and

123
00:06:03.300 --> 00:06:06.200
 there we only have just the

124
00:06:06.700 --> 00:06:08.000
 ETA 0 and not the loopback.

125
00:06:08.700 --> 00:06:11.700
So there's another way to look at it. Okay, so

126
00:06:11.700 --> 00:06:14.500
 just like we saw an AWS this

127
00:06:14.500 --> 00:06:17.500
 routes we have the exact same thing on the Linux

128
00:06:17.500 --> 00:06:19.200
 those two Linux has its own route table.

129
00:06:19.900 --> 00:06:22.200
And it's just like what we saw up in

130
00:06:22.200 --> 00:06:25.200
 AWS. There's a source of destination and their rules

131
00:06:25.200 --> 00:06:28.100
 and then these rules are matched and depending on

132
00:06:28.100 --> 00:06:31.400
 what rule matches that's where the pack will be sent. So once again,

133
00:06:31.400 --> 00:06:34.000
 we can go ahead and use the IP Command to show

134
00:06:34.600 --> 00:06:35.300
 our route table.

135
00:06:36.200 --> 00:06:38.300
And we use the route subcommand.

136
00:06:39.100 --> 00:06:41.800
And then we could use list so IP route list.

137
00:06:42.800 --> 00:06:45.200
Okay. So the the first thing that

138
00:06:45.200 --> 00:06:49.900
 we can see here is we have a default via 10.1.1

139
00:06:48.900 --> 00:06:51.400
 through device each zero.

140
00:06:51.400 --> 00:06:54.700
 So this is the default route. So if no other rule

141
00:06:54.700 --> 00:06:58.100
 matches in our route, it'll send the packet to

142
00:06:57.100 --> 00:07:00.200
 this IP address, which is

143
00:07:00.200 --> 00:07:03.900
 actually our default gateway inside Amazon Linux and

144
00:07:03.900 --> 00:07:07.700
 it'll use our ET h0 device

145
00:07:06.700 --> 00:07:09.200
 to send it out which makes sense

146
00:07:09.200 --> 00:07:12.800
 because that is the only one that we have that's actually connected to a network outside

147
00:07:12.800 --> 00:07:13.500
 of our host.

148
00:07:14.600 --> 00:07:17.400
Here you have a full address range

149
00:07:17.400 --> 00:07:20.300
 which is saying so this is basically that subnet we

150
00:07:20.300 --> 00:07:23.600
 created the 10.0.1 and it's saying anything

151
00:07:23.600 --> 00:07:26.300
 any address or any packet Bound for

152
00:07:26.300 --> 00:07:27.800
 an IP address in this range.

153
00:07:28.800 --> 00:07:31.700
Use the E the ethernet 0

154
00:07:31.700 --> 00:07:32.000
 device.

155
00:07:34.200 --> 00:07:37.500
So that's what that rule or route says and then

156
00:07:37.500 --> 00:07:40.400
 down here. This route is used

157
00:07:40.400 --> 00:07:43.900
 for zero configuration. And

158
00:07:43.900 --> 00:07:46.200
 those packets don't ever really leave the host,

159
00:07:46.200 --> 00:07:48.500
 but they're bound to the et80.

160
00:07:49.600 --> 00:07:53.100
Not really important for here, but just to know so those three

161
00:07:52.100 --> 00:07:54.100
 routes are set.

162
00:07:55.200 --> 00:07:58.600
Okay, so we've discussed the interfaces we've discussed the

163
00:07:58.600 --> 00:08:01.900
 addresses IP addresses and we've discussed routes so

164
00:08:01.900 --> 00:08:05.300
 the next thing to discuss is services that

165
00:08:04.300 --> 00:08:07.700
 can send and receive network connections they

166
00:08:07.700 --> 00:08:10.600
 open a port on your Linux hose so we have

167
00:08:10.600 --> 00:08:13.200
 the ability to see those active connections and the ports

168
00:08:13.200 --> 00:08:16.700
 they're listening on by using another command called socket statistics

169
00:08:16.700 --> 00:08:19.200
 or SS for short. So the first

170
00:08:19.200 --> 00:08:22.800
 thing we could do let me clear the screen is we can do a summary

171
00:08:22.800 --> 00:08:26.200
 of all the activity on this

172
00:08:25.200 --> 00:08:29.000
 host network activity meaning ports

173
00:08:28.100 --> 00:08:31.700
 in connections. So do SS Dash

174
00:08:31.700 --> 00:08:34.200
 ass for summary and you can hear

175
00:08:34.200 --> 00:08:37.800
 we just get an overall view you can see that there's six TCP

176
00:08:37.800 --> 00:08:40.700
 connections one is established at

177
00:08:40.700 --> 00:08:43.500
 the moment and in Network Speak established means that it's alive

178
00:08:43.500 --> 00:08:44.300
 connection. Yeah.

179
00:08:45.100 --> 00:08:48.300
And I I know what this connection is, but

180
00:08:48.300 --> 00:08:51.300
 you could assume this is my SSH connection

181
00:08:51.300 --> 00:08:54.200
 into the host. You can see that there's none closed none

182
00:08:54.200 --> 00:08:58.200
 orphan and none in time. Wait, those are just different states of

183
00:08:57.200 --> 00:09:00.600
 of a network connection and here

184
00:09:00.600 --> 00:09:05.100
 you can see that you have UDP to TCP inet

185
00:09:03.100 --> 00:09:06.300
 and so you'll have

186
00:09:06.300 --> 00:09:10.600
 just a list and then this is ipv4 connections and

187
00:09:10.600 --> 00:09:11.700
 this is that pv6.

188
00:09:12.600 --> 00:09:15.500
AWS has comes with both you can have an ipv4

189
00:09:15.500 --> 00:09:17.100
 or IPv6 addresses.

190
00:09:17.900 --> 00:09:20.200
On your host right now. We're just using

191
00:09:20.200 --> 00:09:23.300
 a tcp/ipv version 4 stuff. Okay,

192
00:09:23.300 --> 00:09:25.100
 so there's our summary.

193
00:09:26.100 --> 00:09:27.500
So the next thing we want to do.

194
00:09:29.300 --> 00:09:32.700
So the next thing we want to do is we want to drill down a little bit further. I'll clear

195
00:09:32.700 --> 00:09:35.400
 the screen here. So what we want to see is we want to see what like

196
00:09:35.400 --> 00:09:38.200
 what active connections are right now on our host.

197
00:09:39.200 --> 00:09:42.400
And we're gonna use these flags. Let

198
00:09:42.400 --> 00:09:42.700
 me show.

199
00:09:43.700 --> 00:09:46.300
So we do need pseudo because of

200
00:09:46.300 --> 00:09:49.500
 the pflag and I'll explain that in a second. But so the the

201
00:09:49.500 --> 00:09:52.700
 T in here stands for we want TCP connections the

202
00:09:52.700 --> 00:09:55.400
 n stands for don't do

203
00:09:55.400 --> 00:09:58.400
 Port conversions. Don't don't do any

204
00:09:58.400 --> 00:10:01.600
 host name lookups don't do any kind of DNS it's

205
00:10:01.600 --> 00:10:04.500
 faster and it allows us to see the actual port numbers

206
00:10:04.500 --> 00:10:07.500
 instead of Port names like SSH or

207
00:10:07.500 --> 00:10:10.400
 HTTP and then the piece shows what

208
00:10:10.400 --> 00:10:13.300
 process is using that socket without using

209
00:10:13.300 --> 00:10:16.500
 the sudo elevated privileges. You won't be able to see what

210
00:10:16.500 --> 00:10:19.200
 process is actually using it because it requires a

211
00:10:19.200 --> 00:10:23.000
 little bit permission. So let's go ahead and hit return and as

212
00:10:22.300 --> 00:10:25.500
 I suspected and maybe you did

213
00:10:25.500 --> 00:10:28.900
 as well. We have one connection here and one

214
00:10:28.900 --> 00:10:29.800
 TCP connection.

215
00:10:30.600 --> 00:10:32.100
And we can see that it's established.

216
00:10:33.700 --> 00:10:36.800
And it is on this IP address,

217
00:10:36.800 --> 00:10:39.100
 which is the IP address

218
00:10:39.100 --> 00:10:42.500
 of our et80 you saw and for Port 22,

219
00:10:42.500 --> 00:10:43.800
 which we know is SSH.

220
00:10:45.200 --> 00:10:48.900
This is my public IP address and this

221
00:10:48.900 --> 00:10:51.200
 is the source for the source Port

222
00:10:51.200 --> 00:10:55.000
 that this connection is originating from and here's the process a

223
00:10:54.400 --> 00:10:57.300
 little hark because I know it splits the screen, but you can

224
00:10:57.300 --> 00:11:00.900
 see here that the process is used by sshd which

225
00:11:00.900 --> 00:11:03.100
 is the server of SSH.

226
00:11:04.400 --> 00:11:07.400
Okay, let me clear the screen here. Okay, so there's one more

227
00:11:07.400 --> 00:11:09.400
 useful command here that

228
00:11:10.400 --> 00:11:13.100
A socket statistic command that you should know and this is

229
00:11:13.100 --> 00:11:16.300
 to see if a service is listening on a port

230
00:11:16.300 --> 00:11:19.400
 like you started up an application. You started up a web server. You

231
00:11:19.400 --> 00:11:22.800
 want to make sure it's listening on the port that you expected to?

232
00:11:22.800 --> 00:11:25.700
 Well, you can do the same

233
00:11:25.700 --> 00:11:28.400
 basically the same command we just did but we're gonna do you add

234
00:11:28.400 --> 00:11:31.100
 a l flag to this for any listening Port? So

235
00:11:31.100 --> 00:11:32.600
 we're gonna do sudo Dash.

236
00:11:33.400 --> 00:11:36.600
Ss-t and LP, which

237
00:11:36.600 --> 00:11:39.600
 is TCP. No, don't do Port

238
00:11:39.600 --> 00:11:43.000
 naming socket or DNS resolution L

239
00:11:42.300 --> 00:11:45.600
 for listening and P for the process again. And

240
00:11:45.600 --> 00:11:46.500
 so we'll hit return.

241
00:11:47.300 --> 00:11:51.400
Okay, so you can see here. We have multiple returns here

242
00:11:51.400 --> 00:11:54.700
 so we can see like this first line right here. We have

243
00:11:54.700 --> 00:11:58.800
 we have some sort of service listening on

244
00:11:58.800 --> 00:12:01.300
 Port 1111 on any in

245
00:12:01.300 --> 00:12:03.100
 this basically means on any interfaces.

246
00:12:04.400 --> 00:12:05.900
inside the ec2 host

247
00:12:07.300 --> 00:12:10.400
and it says it'll accept basically any connection from

248
00:12:10.400 --> 00:12:13.800
 anywhere and this is the RPC bind process.

249
00:12:14.800 --> 00:12:17.600
So here on line two, which is what we just saw earlier.

250
00:12:17.600 --> 00:12:20.300
 This is SSH server listening on Port

251
00:12:20.300 --> 00:12:23.500
 22, except any connections and this

252
00:12:23.500 --> 00:12:26.500
 is the sshd server. So this one right here

253
00:12:26.500 --> 00:12:29.100
 is you could tell so this is only listening on

254
00:12:29.100 --> 00:12:32.300
 our loopback device so localhost, but Port 25,

255
00:12:32.300 --> 00:12:35.300
 which is SMTP Port. So email

256
00:12:36.200 --> 00:12:39.500
And this one it says Master here,

257
00:12:39.500 --> 00:12:42.100
 but this is what postfix postfix. This is

258
00:12:42.100 --> 00:12:45.100
 the postfix mail server. And this is what it calls its primary.

259
00:12:45.800 --> 00:12:46.700
primary server

260
00:12:47.400 --> 00:12:50.600
and these two down here are the same as above except these

261
00:12:50.600 --> 00:12:53.800
 are IPv6 not ipv4 so

262
00:12:53.800 --> 00:12:55.200
 you can ignore those for right now.

263
00:12:55.900 --> 00:12:58.100
Okay. So with all that

264
00:12:58.100 --> 00:13:00.500
 out of the way, let's head back over for a recap.

265
00:13:01.300 --> 00:13:04.900
Okay, so let's talk about what we did in this video you learned

266
00:13:04.900 --> 00:13:07.300
 about how network interfaces is a started on boot by

267
00:13:07.300 --> 00:13:10.300
 System D. You use the IP and socket statistics

268
00:13:10.300 --> 00:13:13.200
 commands to learn about the network interfaces and ports

269
00:13:13.200 --> 00:13:13.900
 on your Linux host.

270
00:13:15.700 --> 00:13:18.500
In the next video, you'll learn how to manage services and

271
00:13:18.500 --> 00:13:20.800
 processes inside Linux using systemd.
