Domain Name System
A device or local network that is connected to the internet gets an IP address assigned which locates and identifies it globally which is comparable to the identification of a location via a postal address (or geocoordinates). Because humans are bad at remembering and recognizing the seemingly arbitrary numbers of an IP address, we use domain names like example.org
, wikipedia.org
or roadmappy.com
to access websites. The domain name system is basically like a phone book for websites. A browser learns a domain name only when a user enters the domain in the URL bar, but the browser does not necessarily know the IP address corresponding to that domain. In that case, the browser uses the domain name to look up the corresponding IP address.
You can look up the IP address of a website yourself
In Chrome you can see the IP of a website: chrome://net-internals/?#dns. Alternatively, you can open a terminal window. For example, Command Prompt (CMD) or PowerShell on Windows, Terminal on Mac, or the Linux Shell / Command Line. Once you open a terminal window you can type `ping` followed by the hostname you want to know the IP address of. So for example: ping example.com
.
So, the browser first checks if it already visited this domain name and has the IP address stored in its internal DNS cache. If the browser cannot find an IP address it makes a request to a DNS server to find out the IP address of the domain name. On average this takes 20 - 120 milliseconds. But often this request can be skipped to deliver the requested website faster if the address was already cached. You can compare this to first checking in your bookshelf for a particular book you want to read before going the long way to the library. Once the IP address is resolved the browser can make a request the the IP address and receive a website from the corresponding server.
There are some more details about recursive DNS servers. DNS servers build a hierarchy so if the first server doesn't find an entry for the domain the browser is searching for, the server will ask other DNS servers until an entry is found or an error is returned. This is a bit simplified (there are root, ISP DNS, TLD... involved).
Further reading
- DNS Explained in 100 Seconds https://www.youtube.com/watch?v=UVR9lhUGAyU
- Host file: You can add entries in the host file of your computer to redirect traffic to another domain on the operating system level or block certain domain names (by redirecting traffic into the void
0.0.0.0
). Operating systems provide programming commands (so called sockets API) so that applications can access the internet.
- Pi-hole is software that acts as a DNS server while blocking traffic to certain sites like ads, malware and gambling. You can install Pi-hole on a cheap Raspberry Pi and either configure the PI as a DNS in your home router or configure your devices (clients) to use only the Pi as the DNS server to look up IP addresses. The PI itself is forwarding IP address requests for certain domains to a normal DNS server but only if the domain does not occur on its block list. So, the PI is basically acting like a bouncer in front of a club only allowing certain traffic to pass. You could also configure a Pi-Hole to block certain hostnames, e.g. you could block instagram.com if you want to spent less time on social media.
- If you are running your own server for example to host a Nextcloud (self-hosted dropbox or google drive alternative) or to do smart home automation stuff. You might also have a look into dynamic DN services like twoDNS which allows you to work with a domain name instead of using an IP address that might change every 24 hours.