https://youtu.be/27r4Bzuj5NQ?si=gcPo5x0694IrIpjR
The Domain Name System (DNS) acts as the internet's GPS, guiding your online journey from memorable landmarks (domain names) to precise numerical coordinates (IP addresses). Much like how GPS translates a destination name into latitude and longitude for navigation, DNS translates human-readable domain names (like www.example.com) into the numerical IP addresses (like 192.0.2.1) that computers use to communicate.
When you enter a domain name (e.g., www.example.com) into your browser, your computer must find its IP address before it can connect to the website.
Check the Hosts File – The operating system first checks the local hosts file. If a matching entry exists, it uses that IP address and skips DNS entirely.Check the Local DNS Cache – If no hosts file entry is found, the computer checks its DNS cache for a previously stored IP address.Query the DNS Resolver – If the IP is not cached locally, the computer sends a DNS query to a DNS resolver (typically provided by your ISP or a public DNS service such as Google or Cloudflare).Root Name Server – If the resolver does not have the answer cached, it queries a root name server, which directs it to the appropriate Top-Level Domain (TLD) server (e.g., .com, .org).TLD Name Server – The TLD server identifies the authoritative name server responsible for the requested domain.Authoritative Name Server – This server contains the domain's DNS records and returns the correct IP address.Return and Cache the Result** – The DNS resolver sends the IP address back to the computer and caches it for future requests. The computer also stores it in its local DNS cache.Connect to the Website – Using the returned IP address, the computer establishes a connection with the web server and loads the requested website.Summary Flow:
Hosts File → Local DNS Cache → DNS Resolver → Root Server → TLD Server → Authoritative Name Server → IP Address Returned → Connect to Website
The hosts file is a simple text file used to map hostnames to IP addresses, providing a manual method of domain name resolution that bypasses the DNS process. While DNS automates the translation of domain names to IP addresses, the hosts file allows for direct, local overrides. This can be particularly useful for development, troubleshooting, or blocking websites.
The hosts file is located in C:\Windows\System32\drivers\etc\hosts on Windows and in /etc/hosts on Linux and MacOS. Each line in the file follows the format:
txt
<IP Address> <Hostname> [<Alias> ...]