Fundamentals 18 min read

What Really Happens When You Type a URL? A Deep Dive into DNS and Web Access

This comprehensive guide explains every step of how a browser retrieves a webpage—from DNS lookup and TCP handshake to HTTP request handling—while also covering DNS hierarchy, terminology, using dig for tracing, and practical setups of BIND and dnsmasq DNS servers on Linux.

MaGe Linux Operations
MaGe Linux Operations
MaGe Linux Operations
What Really Happens When You Type a URL? A Deep Dive into DNS and Web Access

What Happens After Entering a URL

This classic question reveals the depth of knowledge from beginner to expert, covering the entire process of how a browser retrieves a web page.

1. User Access Flow

0. Client ensures network connectivity
1. Client enters URL www.yuchaoit.cn in browser
2. Client performs DNS lookup to obtain IP address
3. Client initiates TCP three‑way handshake with the server IP
4. After TCP connection, client sends HTTP request (multiple requests may be made)
5. Server parses request and sends HTTP response (multiple responses)
6. Browser receives response, parses and renders the page
7. Client closes connection with TCP four‑way handshake

2. Key Technical Terms

1. Domain name
2. DNS resolution
3. TCP/IP three‑way handshake
4. TCP/IP four‑way termination
5. HTTP request
6. HTTP response

1. DNS Domain Structure

Domain names use a hierarchical tree structure. A fully qualified domain name consists of labels separated by dots, forming root, top‑level domain, second‑level domain, and subdomains.

Root Zone (.)

There are 13 root name servers worldwide. One primary root server is located in the United States; the remaining 12 are distributed globally.

Top‑Level Domain (TLD)

The last label of a domain name, e.g., .cn or .com.

Second‑Level Domain

The label directly left of the TLD, e.g., yuchaoit in yuchaoit.cn.

Third‑Level Domain

Subdomains under the second‑level domain.

2. DNS Server Hierarchy (Resolution Process)

Textual Description of DNS Resolution

## DNS Resolution
1. Browser checks local /etc/hosts for a static mapping.
2. If not found, it queries the configured DNS server (usually provided by the ISP).
3. The local DNS server first checks its cache; if missing, it recursively queries the root servers.
4. Root servers return the address of the appropriate TLD server.
5. The local DNS server queries the TLD server, which returns the authoritative name server for the domain.
6. The authoritative server returns the final A record (IP address), which is cached locally for future queries.

3. DNS Terminology

Recursive Query

Similar to recursively creating directories with mkdir -p. If the local DNS server lacks the record, it follows the chain of queries up to the root until it obtains the answer.

Iterative Query

The DNS server does not return the final answer directly but points the client to another DNS server, which repeats the process until the answer is found.

DNS Cache

Stores domain‑to‑IP mappings close to the client to reduce the number of recursive queries.

TTL (Time To Live)

Specifies how long a DNS record may be cached before it expires and must be refreshed.

4. Using the dig Command

Install the utility: yum install bind-utils -y Example to trace the resolution of www.yuchaoit.cn: dig +trace www.yuchaoit.cn The command shows the sequence of queries from root servers to the authoritative server and finally the A record (123.206.16.61).

5. Adding DNS Records in Tencent Cloud

Typical record types are illustrated below.

To add an A record for a third‑level domain:

# Example A record
linux.yuchaoit.cn.    IN    A    123.206.16.61

6. Building Your Own DNS Server with BIND

Install BIND on a server (e.g., 172.16.1.61) and configure /etc/named.conf and zone files.

# Sample zone definition
zone "laoliulinux.cn" IN {
    type master;
    file "laoliulinux.cn.zone";
    allow-update { none; };
};

Sample laoliulinux.cn.zone file:

$TTL 1D
@   IN  SOA @ rname.invalid. (
        0       ; serial
        1D      ; refresh
        1H      ; retry
        1W      ; expire
        3H )    ; minimum
    IN  NS  @
    IN  A   172.16.1.61
    IN  AAAA    ::1
www IN  A   172.16.1.61
linux   IN  A   172.16.1.61

Start the service and verify it is listening on port 53.

7. Lightweight DNS with dnsmasq

After stopping BIND, install dnsmasq: yum install dnsmasq -y Configure /etc/dnsmasq.conf to forward queries and add local host mappings:

resolv-file=/etc/resolv.dnsmasq.conf
listen-address=172.16.1.61
addn-hosts=/etc/hosts.dnsmasq.conf

Example /etc/hosts.dnsmasq.conf:

172.16.1.61 master-61
172.16.1.5  slb-5
172.16.1.6  slb-6
172.16.1.7  web-7
172.16.1.8  web-8
172.16.1.9  web-9
172.16.1.31 nfs-31
172.16.1.41 rsync-41
172.16.1.51 db-51

Start dnsmasq and point client machines to the server (e.g., nameserver 172.16.1.61 in /etc/resolv.conf).

References

Original article: https://www.cnblogs.com/btcm409181423/p/18075535 (copyright belongs to the author).

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

LinuxDNSDomain Name Systemdig
MaGe Linux Operations
Written by

MaGe Linux Operations

Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.