1
00:00:00,810 --> 00:00:06,780
In this series of lectures, we get our networking basics right.

2
00:00:06,800 --> 00:00:15,200
We look at basic networking concepts like Switching, Routing, Gateways etc.  We then understand DNS,  and

3
00:00:15,200 --> 00:00:18,290
then we get a basic introduction to core DNS.

4
00:00:18,680 --> 00:00:28,930
We look at how to configure DNS settings on a Linux system within understand basics of network namespace

5
00:00:28,930 --> 00:00:31,060
in Linux.

6
00:00:31,160 --> 00:00:36,060
I am not going to bore you with theories on OSI models or network layers

7
00:00:36,260 --> 00:00:42,890
We're just brushing up enough networking to understand the rest of the section in this course.

8
00:00:42,960 --> 00:00:48,470
Now we don't just go through the concepts we see how these are configured on our systems specifically

9
00:00:48,770 --> 00:00:51,020
from a Linux perspective.

10
00:00:51,020 --> 00:00:53,670
So there are going to be lots of commands.

11
00:00:53,870 --> 00:01:00,680
We look at this from a system admins and the application developers perspective and not necessarily

12
00:01:00,680 --> 00:01:07,390
from a network engineers that way later on when we discuss these in the context of our course.

13
00:01:07,580 --> 00:01:13,460
You know what we were talking about where to look for information where things are configured how to

14
00:01:13,460 --> 00:01:22,480
troubleshoot etc. And of course as always if these seem to be too basic for you if you or if you're

15
00:01:22,500 --> 00:01:29,370
already good with networking in Linux feel free to skip these lectures and go straight to the ones on

16
00:01:29,370 --> 00:01:30,530
Kubernetes.

17
00:01:30,660 --> 00:01:31,760
So let's get started.

18
00:01:33,370 --> 00:01:34,250
So what is a

19
00:01:34,320 --> 00:01:35,160
Network.

20
00:01:35,320 --> 00:01:41,650
We have two computers A & B – laptops, desktops, VMs on the cloud, wherever.

21
00:01:41,650 --> 00:01:43,870
How does system A reach B?

22
00:01:43,880 --> 00:01:51,070
We connect them to a switch, and the switch creates a network containing the two systems. To connect

23
00:01:51,070 --> 00:01:52,420
them to a switch

24
00:01:52,420 --> 00:02:00,100
we need an interface on each host. Physical or virtual depending on the host to see the interfaces for

25
00:02:00,100 --> 00:02:00,970
the host.

26
00:02:01,000 --> 00:02:03,730
We use the IP link command.

27
00:02:04,060 --> 00:02:11,270
In this case, we look at the interface named eth0 that we will be using to connect to the switch.

28
00:02:11,320 --> 00:02:13,960
Let's assume it's a network with the address.

29
00:02:13,960 --> 00:02:16,900
192.168.1.0.

30
00:02:17,020 --> 00:02:21,270
We then assign the systems with IP addresses on the same network.

31
00:02:21,310 --> 00:02:29,400
For this, we use the command ip addr. Once the links are up, and the IP addresses are assigned,

32
00:02:29,410 --> 00:02:37,150
The computers can now communicate with each other through the switch the switch can only enable communication

33
00:02:37,300 --> 00:02:44,470
within and network which means it can receive packets from a host on the network and deliver it to other

34
00:02:44,470 --> 00:02:47,190
systems within the same network.

35
00:02:48,740 --> 00:02:56,450
Say we have another network containing systems C & D at address 192.168.2.0.

36
00:02:56,450 --> 00:03:02,570
The Systems have IP address 192.168.2.10 and 2.11 respectively.

37
00:03:02,600 --> 00:03:07,430
How does a system in one network reach a system in the other.

38
00:03:07,430 --> 00:03:16,040
How does System B with the IP 192.168.1.11 reach system C with the IP 2.10 on the

39
00:03:16,130 --> 00:03:17,690
other network.

40
00:03:17,990 --> 00:03:27,320
That’s where a Router comes in. A Router helps connect two networks together. It is an intelligent device,

41
00:03:27,320 --> 00:03:34,850
so think of it as another server with many network ports. Since it connects to the two separate networks,

42
00:03:34,850 --> 00:03:41,000
it gets two IPs assigned. One on each network. In the first network

43
00:03:41,000 --> 00:03:49,400
we assign it an IP address 192.168.1.1  and in the second we assign it an IP 192.168.2.1.

44
00:03:49,400 --> 00:03:55,260
Now we have a router connected to the two networks that can enable communication between them.

45
00:03:55,580 --> 00:04:02,720
Now, when system B tries to send a packet to system C, how does it know where the router is on the network

46
00:04:02,960 --> 00:04:08,930
to send the packet through the router is just another device on the network.

47
00:04:08,930 --> 00:04:18,150
there could be many other such devices. That’s where we configure the systems with a gateway or a route.

48
00:04:18,960 --> 00:04:25,800
If the network was a room, the gateway is a door to the outside world  to other networks or to the

49
00:04:25,800 --> 00:04:27,040
Internet.

50
00:04:27,120 --> 00:04:35,040
The systems need to know where that door is to go through that to see the existing routing configuration

51
00:04:35,100 --> 00:04:42,540
on a system run the route command. It displays the kernels routing table and within that, as you can

52
00:04:42,540 --> 00:04:45,290
see there are no routing configurations

53
00:04:45,300 --> 00:04:46,450
as of now.

54
00:04:46,450 --> 00:04:53,640
So in this condition your system B will not be able to reach system C it can only reach other systems

55
00:04:53,970 --> 00:05:03,110
within the same network in the range 192.168.1.0. To configure a gateway on system B to reach the

56
00:05:03,110 --> 00:05:10,750
systems on network 192.168.2.0, run the ip route add command, and specify that you can reach the

57
00:05:10,760 --> 00:05:19,340
192.168.2.0 network through the door or gateway at 192.168.1.11. Running the route

58
00:05:19,550 --> 00:05:26,690
command again shows that we have a route added to reach the 192.168.2.0 series network through the

59
00:05:26,690 --> 00:05:28,700
router.

60
00:05:28,710 --> 00:05:32,430
Now remember this has to be configured on all the systems.

61
00:05:32,440 --> 00:05:39,730
For example, if the system C is to send a packet to system B, then you need to add a route on system C’s

62
00:05:39,730 --> 00:05:46,340
routing table to access network 192.168.1.0 through the router configured with the IP address

63
00:05:46,350 --> 00:05:56,420
192.168.2.1.  Now suppose these systems need access to the Internet. Say they need access to Google at

64
00:05:56,430 --> 00:06:02,330
172.217.194.0 network on the internet. So you connect the router to the internet.

65
00:06:02,720 --> 00:06:10,290
and then add a new road in your routing table to road all traffic to the network 172.217.194

66
00:06:10,610 --> 00:06:17,420
through your router there are so many different sites on different networks on the Internet instead

67
00:06:17,420 --> 00:06:23,870
of adding a routing table entry for these same routers IP address for each of those networks you can

68
00:06:23,870 --> 00:06:31,740
simply say for any network that you don't know a route to use this router as the default gateway.

69
00:06:32,090 --> 00:06:38,510
This way any request to any network outside of your existing network goes to this particular router.

70
00:06:39,470 --> 00:06:46,970
So in a simple setup like this, all you need is a single routing table entry with a default gateway set

71
00:06:46,970 --> 00:06:49,700
to the routers IP address.

72
00:06:49,700 --> 00:06:54,630
Remember instead of the word default you could also say 0.0.0.0.0.

73
00:06:54,830 --> 00:06:57,450
It means any IP destination.

74
00:06:57,680 --> 00:07:02,640
Both of these lines mean the same thing. A 0.0.0.0

75
00:07:02,660 --> 00:07:08,890
Entry in the Gateway field indicates that you don't need a gateway for example in this case for system

76
00:07:08,900 --> 00:07:14,370
C to access any devices in the 192.168.2.0 network.

77
00:07:14,480 --> 00:07:20,930
It doesn't need a gateway because it is in its own network. But say you have multiple routers in your

78
00:07:20,930 --> 00:07:29,750
network one for the Internet another for the internal private network then you will need to have two

79
00:07:29,750 --> 00:07:32,510
separate entries for each network.

80
00:07:32,510 --> 00:07:39,320
One entry for the internal private network and another entry with the default gateway for all other

81
00:07:39,320 --> 00:07:42,240
networks including public networks.

82
00:07:42,260 --> 00:07:45,750
So if you are having issues  reaching internet from your systems,

83
00:07:46,010 --> 00:07:53,520
This routing table and the default gateway configuration is a good place to start let us know look at

84
00:07:53,700 --> 00:07:57,190
how we can set up a linux host as a rotor.

85
00:07:57,210 --> 00:07:58,590
Let's start with a simple setup.

86
00:07:59,650 --> 00:08:06,530
I have 3 hosts A, B and C.  A & B are connected to a network 192.168.1 and B

87
00:08:06,530 --> 00:08:14,360
& C to another on 192.168.2. So host B is connected to both the networks using two interfaces eth0

88
00:08:14,420 --> 00:08:24,550
A has IP 192.168.1.5, C has 192.168.2.5 and B has an IP on both the networks.

89
00:08:24,550 --> 00:08:28,280
192.168.1.6 and 192.168.2.6.

90
00:08:28,340 --> 00:08:31,800
How do we get A to talk to C? Basically,

91
00:08:31,850 --> 00:08:39,160
if I try to ping 192.168.2.5 from A, it would say Network is Unreachable.  And by now we know why that is.

92
00:08:39,290 --> 00:08:45,840
Host A has no idea how to reach a network at 192.168.2.

93
00:08:45,920 --> 00:08:54,260
We need to tell host A that the door or gateway to network 2 is through host B.  And we do that by adding

94
00:08:54,440 --> 00:09:03,350
adding a routing table entry. We add a route to access network 192.168.2 via the gateway

95
00:09:03,350 --> 00:09:12,130
192.168.1.6. If the packets where to get through to Host C, Host C will have to send back responses

96
00:09:12,130 --> 00:09:21,910
to Host A. When Host C tries to reach Host A at 192.168.1 network, it would face the same issue. So

97
00:09:21,910 --> 00:09:29,650
we need to let know Host C know that it can reach Host A through Host B which is acting as a router.  So we

98
00:09:29,650 --> 00:09:36,520
add a similar entry into Host C’s routing table. This time we say to reach network 192.168.1.0,

99
00:09:36,910 --> 00:09:46,460
talk to Host B at 192.168.2.6. When we try to ping now, we no longer get the Network Unreachable

100
00:09:46,490 --> 00:09:54,890
error message that means our routing entries are right but we still don't get any response back. By default

101
00:09:55,220 --> 00:10:02,420
in Linux, packets are not forwarded from one interface to the next for example packets received on eth0

102
00:10:02,430 --> 00:10:11,470
on host, B are not forwarded to elsewhere through eth 1 this is this way for security reasons.

103
00:10:11,480 --> 00:10:17,720
For example, if you had eth0 connected to your private network and eth1 to a public network, we

104
00:10:17,720 --> 00:10:23,450
don't want anyone from the public network to easily send messages to the private network unless you

105
00:10:23,540 --> 00:10:25,410
explicitly allow that.

106
00:10:25,700 --> 00:10:30,170
But in this case since we know that both are private networks and it is safe to enable communication

107
00:10:30,200 --> 00:10:37,810
between them we can allow host B to forward packets from one network to the other whether a host can

108
00:10:37,810 --> 00:10:47,190
forward packets between interfaces is governed by a setting in this system at file /proc/sys/net/ipv4/ip

109
00:10:47,190 --> 00:10:56,250
forward by default, the value in this file is set to 0 meaning no forward set

110
00:10:56,280 --> 00:10:59,830
this to 1 and you should see the pings go through.

111
00:10:59,840 --> 00:11:06,150
Now remember simply setting this value does not persist the changes across reboots for that you must

112
00:11:06,150 --> 00:11:12,020
modify the same value in the /etc/sysctl.conf file.

113
00:11:12,630 --> 00:11:16,080
So let's take away some key commands from this lecture.

114
00:11:16,080 --> 00:11:23,650
These will be handy in the upcoming lectures IP link is to list and modify interfaces on the host

115
00:11:23,670 --> 00:11:31,920
ip addr command is to see the ip addresses assigned to those interfaces  ip addr add command is used to set

116
00:11:32,190 --> 00:11:34,860
IP addresses on the interfaces.

117
00:11:34,860 --> 00:11:40,740
Now remember changed made using these commands are only valid till a restart. If you want to persist these

118
00:11:40,740 --> 00:11:49,110
changes you must set them in the /etc/network/interfaces file. ip route or simply the route command

119
00:11:49,110 --> 00:11:56,500
is used to view the routing table. And ip route add command is used to add entries into the routing table.

120
00:11:56,550 --> 00:12:02,290
And finally remember the command to check if IP forwarding is enabled on a host.

121
00:12:02,310 --> 00:12:08,480
If you're working with a house configured as a router Well that's it for this lecture in the next lecture.

122
00:12:08,500 --> 00:12:11,100
We'll discuss about DNS configurations.
