Day 2/100daysofK8s

Parthvi Vala
3 min readApr 9, 2021

--

/etc/hosts is the place where we keep a map of IP address and their DNS.

For an entry, for e.g. —

127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4

pinging any of the domain names will call 127.0.0.1 .

This map just stays on the system though, so I could add another name, say Sherlock to the above list and then run ping Sherlock and it would still ping 127.0.0.1. Consider 2 systems in a network, system1 could know 127.0.0.1 as Sherlock, while system2 could know it as Holmes . Every system can have it’s own map.

Over the time this map could grow long, so we use a DNS server instead, that has this map with all the systems IP. The system needs to know IP of this DNS server which is present inside /etc/resolv.conf under nameserver . So, anytime the system encounters a hostname that it does not know about, it asks the DNS server. If a host’s IP address changes, updating it in the DNS server will do.

/etc/hosts acts as a local nameserver, while nameserver in /etc/resolv.conf acts as a global(network-scoped) nameserver. If a system wanted to define IP-DNS map for it’s local use, it can put that map in /etc/hosts , but if it wants every other system on the network to know about it, it puts it up in the DNS server.

For any new hostname, server first finds it’s relevant IP address in /etc/hosts , and then in the nameserver. Local takes preference over global.

8.8.8.8 is Google’s DNServer that has. We can add Forward All 8.8.8.8 in our network’s nameserver, to forward all unknown domain name searches to 8.8.8.8 .

Domain Name grouping —

www.google.com. is the root, .com is the top level domain name, google is the domain name assigned, and www is the subdomain.

E.g. of other subdomains are — drive(drive.google.com), maps(maps.google.com), apps(apps.google.com), accounts(accounts.google.com), play (play.google.com)etc. These subdomains help group the domains.

There might be multiple nameserver used while looking for the IP address.

While looking for the IP address of an unknown domain name, we first hit our local/network’s nameserver. It then forwards the search to a nameserver on the internet, which then looks in the subdomain’s nameserver, which then leads to the company’s nameserver.

The following can be the chain while searching an IP address for apps.google.com

Local DNS — Root DNS — .com DNS — Google DNS

To fast the process, Local DNS might keep a cache of the IP for a few seconds/minutes.

If we wanted to use only the subdomain to ping instead of the whole domain, for e.g. — ping apps instead of ping apps.google.com , we can add a new value to search in the etc/resolv.conf file. Like this —

/etc/resolv.conf
---
nameserver 127.0.0.34
search google.com facebook.com

So anytime we ping ping apps it would look for apps.google.com , if it didn’t find one, it would then look for apps.facebook.com .

Record Types — Until now, we only saw a IP address-domain name mapping, but there are 2 other types of records as well — A, AAAA(QuadA records), CNAME.

A — map IPv4 address to domain name
192.168.1.1 — web-server

AAAA — map IPv6 address to domain name
52:54:00:e7:b4:5d — web-server

CNAME — map domain name to domain name, this helps create aliases
food.web-server — eat.web-server, hungry.web-server

DNS lookup tools — 1) ping, 2)nslookup, 3) dig

--

--

No responses yet