The Domain Name System (DNS) is a hierarchical and decentralized naming system for computers, services, or other resources connected to the Internet or a private network.
$ cat /etc/hosts 192.168.1.11 www.backend.com 192.168.1.11 www.backend2.com
You can use either names to read 192.168.1.11
Until the environment grew and the host files got filled with too many entries and managing these became too hard. If one of the servers’ IP changed, you would need to modify the entries in all of these hosts.
That is why we need to move all the entries into a single server who will manage essentially. we call that the DNS Server.
How do we point our host to a DNS Server?
$ cat /etc/resolv.conf # # macOS Notice # # This file is not consulted for DNS hostname resolution, address # resolution, or the DNS query routing mechanism used by most # processes on this system. # # To view the DNS configuration used by this system, use: # scutil --dns # # SEE ALSO # dns-sd(1), scutil(8) # # This file is automatically generated. # nameserver 192.168.1.13
Once this is configured on all of your host, every time a host comes up across a hostname that it does not know about, it looks it up from the DNS Server. If the IP of any of the host was to change, simply update the DNS Server and all host should resolve the new IP address going forward.
What if you have an entry in both places, one in your hosts file and another in DNS?
The host first looks in the local hosts file and then looks at the name server. So, if it finds the entry in the local hosts file, it uses. However, the order can be changed.
How are the records stored in the DNS?
- A: IPv4 IP
- AAAA: IPv6
- CNAME: Mapping one name to another name is called CNAME Record. Name to name mapping.
$ dig www.google.com ; <<>> DiG 9.10.6 <<>> www.google.com ;; global options: +cmd ;; Got answer: ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 54153 ;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1 ;; OPT PSEUDOSECTION: ; EDNS: version: 0, flags:; udp: 4096 ;; QUESTION SECTION: ;www.google.com. IN A ;; ANSWER SECTION: www.google.com. 92 IN A 18.104.22.168 ;; Query time: 3 msec ;; SERVER: 22.214.171.124#53(126.96.36.199) ;; WHEN: Sun Jan 10 15:49:23 KST 2021 ;; MSG SIZE rcvd: 59