1 00:00:07,080 --> 00:00:09,690 - In this video we'll talk about host names. 2 00:00:09,690 --> 00:00:11,320 So how do you manage them? 3 00:00:11,320 --> 00:00:14,490 Well, first let's talk about resolving host names. 4 00:00:14,490 --> 00:00:17,370 DNS is commonly used for host name resolving. 5 00:00:17,370 --> 00:00:19,680 It's a worldwide standard and it's 6 00:00:19,680 --> 00:00:21,640 like you use all the times. 7 00:00:21,640 --> 00:00:23,970 But there is also etc host. 8 00:00:23,970 --> 00:00:26,250 Etc host is used to maintain local list 9 00:00:26,250 --> 00:00:28,443 of host names and matching IP addresses. 10 00:00:29,400 --> 00:00:30,870 Now the interesting question is, 11 00:00:30,870 --> 00:00:33,528 how does etc host relate to DNS? 12 00:00:33,528 --> 00:00:36,877 Well, the order for host name resolution is 13 00:00:36,877 --> 00:00:37,710 in /etc/nsswitch.conf. 14 00:00:41,092 --> 00:00:45,570 So you, need to check out /etc/nsswitch. 15 00:00:45,570 --> 00:00:47,096 It's a name service switch 16 00:00:47,096 --> 00:00:49,170 and it is used to define the order 17 00:00:49,170 --> 00:00:52,025 in which host name resolution should happen. 18 00:00:52,025 --> 00:00:55,920 And the line that you see here might be what you find 19 00:00:55,920 --> 00:00:57,956 in it. Depends on your distribution. 20 00:00:57,956 --> 00:01:01,047 Now the important part is that hosts defines the order 21 00:01:01,047 --> 00:01:03,716 and as long as files comes before DNS, 22 00:01:03,716 --> 00:01:06,676 then etc host is always going to win, 23 00:01:06,676 --> 00:01:08,973 and can be used to override if you want to. 24 00:01:11,416 --> 00:01:14,220 /Etc/resolv.conf is the old standard 25 00:01:14,220 --> 00:01:16,676 for configuring DNS name servers. 26 00:01:16,676 --> 00:01:19,950 And on network manager systems the file can be 27 00:01:19,950 --> 00:01:23,257 written directly, or it is managed by network manager. 28 00:01:23,257 --> 00:01:25,770 And on systemd-networkd systems, 29 00:01:25,770 --> 00:01:27,456 a different approach is used. 30 00:01:27,456 --> 00:01:30,660 Here the file is managed with systemd-resolved. 31 00:01:30,660 --> 00:01:32,836 And etc resolved is a symbolic link to 32 00:01:32,836 --> 00:01:36,870 /run/systemd/resolve/stub-resolv.conf 33 00:01:36,870 --> 00:01:38,905 for automatically managing it. 34 00:01:38,905 --> 00:01:41,490 Let's check out how the simulation works 35 00:01:41,490 --> 00:01:43,563 between etc hosts and DNS. 36 00:01:46,800 --> 00:01:49,620 So here we are on the center s machine and let me 37 00:01:49,620 --> 00:01:53,460 use ping.google.com. And there we go, 38 00:01:53,460 --> 00:01:55,020 We are getting an answer from 39 00:01:55,020 --> 00:01:59,550 142.250.69.238. 40 00:01:59,550 --> 00:02:03,321 Now if I would use etc hosts. And in etc host, 41 00:02:03,321 --> 00:02:08,321 I am setting 192.168.29.2 42 00:02:08,760 --> 00:02:11,253 and I call it google.com. 43 00:02:12,870 --> 00:02:15,150 And then we repeat ping.google.com. 44 00:02:15,150 --> 00:02:20,073 There we can see that google.com is now 192.168.29.2. 45 00:02:21,180 --> 00:02:24,930 Which is obviously not the real Google, but this is just 46 00:02:24,930 --> 00:02:27,060 showing that etc host is always winning 47 00:02:27,060 --> 00:02:29,550 from the DNS configuration. 48 00:02:29,550 --> 00:02:34,337 And that is because of /etc/nsswitch.conf 49 00:02:34,337 --> 00:02:39,337 in which we can find this host's line. Let's look it up. 50 00:02:39,720 --> 00:02:44,040 And in this host's line we have files DNS myhostname. 51 00:02:44,040 --> 00:02:45,930 I'm going to comment it out. 52 00:02:45,930 --> 00:02:49,590 I like commenting it out if I'm playing with configuration 53 00:02:49,590 --> 00:02:52,410 files so that it's easy to get back to the previous 54 00:02:52,410 --> 00:02:55,933 configuration. And now I'm setting to DNS files. 55 00:02:55,933 --> 00:02:57,300 (keyboard clicking) 56 00:02:57,300 --> 00:02:58,680 And what is going to happen now, 57 00:02:58,680 --> 00:03:00,889 if we ping google.com, there you go. 58 00:03:00,889 --> 00:03:03,570 The internet is winning. 59 00:03:03,570 --> 00:03:07,263 So everything because of /etc/nsswitch.conf. 60 00:03:08,583 --> 00:03:11,640 Before continuing, I do advise you to revert 61 00:03:11,640 --> 00:03:13,608 to the original situation. 62 00:03:13,608 --> 00:03:15,699 (keyboard clicking) 63 00:03:15,699 --> 00:03:18,300 There we go. Now it should be working. 64 00:03:18,300 --> 00:03:20,883 Just to avoid some nasty surprises later on.