Back to series
· 19 min read

How Does DNS Work? What Happens After You Enter a URL?


I. What Is DNS?

DNS, short for Domain Name System, is a fundamental service of the Internet.

Computers on a network locate communication targets mainly through IP addresses, but IP addresses are usually composed of numbers or hexadecimal characters, which are not easy for humans to remember.

For example:

www.example.com

might correspond to an IPv4 address:

93.184.216.34

It might also correspond to an IPv6 address.

If you had to remember an IP address every time you visited a website, using the Internet would be a terrible experience.

DNS solves exactly this problem:

Translate human-memorable domain names into IP addresses that computers can use.

1. The Core Functions of DNS

DNS is not just a simple system for mapping domain names to IP addresses; it also takes on a variety of network service responsibilities.

Function Description
Domain name resolution Convert domain names to IP addresses
Reverse resolution Look up the corresponding domain name based on an IP address
Mail routing Locate mail servers via MX records
Service discovery Discover specific services via SRV and other records
Load distribution Return different server addresses via multiple records
Domain verification Publish verification information via TXT and other records
Network policy Publish certain security policies via DNS records

For example:

www.example.com
    Query A record
    Return IPv4 address

mail.example.com
    Query MX record
    Return mail server information

api.example.com
    Query AAAA record
    Return IPv6 address

DNS is an application-layer protocol, typically using UDP or TCP port 53.

Note: DNS is not responsible for establishing TCP connections, nor for transmitting web page content. It is primarily responsible for providing domain-name-related query results.

2. DNS's Position in the Network Architecture

DNS is an application-layer protocol that runs on top of the transport layer.

Network layer Related protocol or technology Main responsibility
Application layer DNS Query the network information corresponding to a domain name
Transport layer UDP, TCP Carry DNS queries and responses
Network layer IPv4, IPv6 Transmit DNS packets across the network
Data link layer Ethernet, Wi-Fi Transmit frames over the local link

A single DNS query may involve multiple network devices and servers, but from the perspective of the application that initiates the query, it usually only needs to send a request to the DNS resolver configured on the local machine.


II. DNS Domain Name Structure: How Are Domain Names Organized?

DNS employs a hierarchical, distributed, tree-shaped naming structure.

For example:

www.blog.example.com.

This domain name is not an indivisible string; it is composed of multiple levels.

1. Domain Name Hierarchy

DNS domain names are organized level by level from right to left.

Part Example Meaning
Root domain . The highest level of the DNS naming system
Top-level domain com Top-level domain
Second-level domain example The registered domain body
Third-level domain blog A subdomain under the second-level domain
Host name www The specific service or host name

Full domain name:

www.blog.example.com.

The trailing dot represents the root domain.

In everyday use, browsers and command-line tools usually allow the trailing root dot to be omitted.

2. DNS's Tree Structure

DNS does not manage all domain names from a single server; instead, it uses hierarchical delegated management.

flowchart TD
    A["DNS root domain ."] --> B["com top-level domain"]
    A --> C["org top-level domain"]
    A --> D["net top-level domain"]
    B --> E["example.com"]
    E --> F["www.example.com"]
    E --> G["mail.example.com"]
    E --> H["api.example.com"]

    style A fill:#E0F0FE,stroke:#93BCE8,color:#1E4976
    style B fill:#DCEFE5,stroke:#8EBFA5,color:#24563F
    style C fill:#DCEFE5,stroke:#8EBFA5,color:#24563F
    style D fill:#DCEFE5,stroke:#8EBFA5,color:#24563F
    style E fill:#E9E2F8,stroke:#B9A5DF,color:#514078
    style F fill:#FFF2CC,stroke:#E6C978,color:#765A18
    style G fill:#FFF2CC,stroke:#E6C978,color:#765A18
    style H fill:#FFF2CC,stroke:#E6C978,color:#765A18

Each level of DNS server usually handles only the zone it manages, and can direct queries for other zones to the corresponding authoritative servers.

3. What Is a DNS Zone?

A Zone, commonly referred to in Chinese as a DNS zone, is the basic unit of DNS management and delegation.

For example:

example.com

can serve as a DNS zone managed by an organization.

The zone can contain:

  • www.example.com
  • api.example.com
  • mail.example.com
  • dev.example.com

A zone is not necessarily equal to a complete branch in the entire domain name tree.

For example, dev.example.com can be separately delegated to another set of DNS servers for management, forming an independent subzone.

A DNS zone usually consists of a set of resource records, and authoritative DNS servers are responsible for serving these records externally.


III. Core Components of DNS: Who Participates in Domain Name Resolution?

A DNS query usually involves multiple roles.

1. DNS Client Stub Resolver

Stub Resolver is a DNS client resolution component that runs in the operating system.

It is usually responsible for:

  • Receiving domain name query requests from applications.
  • Checking the local cache.
  • Sending the query to the configured DNS resolver.
  • Returning the resolution result to the application.

For example, on Linux systems, you can view the traditional DNS resolver configuration via /etc/resolv.conf.

cat /etc/resolv.conf

Example:

nameserver 192.168.1.1
nameserver 1.1.1.1

This indicates that the system is configured with two DNS server addresses.

In actual use, Linux resolution paths may also involve components such as systemd-resolved, NetworkManager, and NSS; you cannot simply assume that all systems directly read this file and send queries.

2. Recursive DNS Resolver

Recursive Resolver, or recursive DNS resolver, also known as a recursive resolution server.

It is responsible for completing domain name resolution on behalf of the client.

Common recursive resolvers include:

  • DNS provided by ISPs.
  • Enterprise internal DNS.
  • DNS forwarding services provided by routers or gateways.
  • Public DNS services.

For example:

  • Google Public DNS: 8.8.8.8
  • Cloudflare DNS: 1.1.1.1
  • Quad9: 9.9.9.9

A recursive resolver usually queries its own cache first. If the cache has no valid result, it then queries other servers in the DNS hierarchy.

3. Root DNS Server

Root DNS Server, i.e., the root DNS server, is responsible for the highest-level guidance in the DNS hierarchy.

Root servers usually do not directly store the IP addresses of all websites.

It mainly knows where the DNS servers for each top-level domain are located.

For example, query:

www.example.com

The root server can return information about the DNS servers for the .com top-level domain.

The global root DNS system consists of 13 logically identified root server names, while in practice it is served by a large number of distributed instances, using technologies such as Anycast to achieve nearby access and redundancy.

4. Top-Level Domain DNS Server

The TLD DNS Server is responsible for managing domain delegation information under a top-level domain.

For example:

  • .com
  • .org
  • .net
  • .cn
  • .jp

When a recursive resolver queries www.example.com, the root server directs it to the top-level domain DNS server for .com.

The TLD server typically returns the authoritative DNS server information for example.com.

5. Authoritative DNS Server

An Authoritative DNS Server is the official data source for a specific DNS Zone.

For example, the authoritative DNS server for example.com may store:

www.example.com    A       93.184.216.34
api.example.com    A       203.0.113.10
mail.example.com   MX      mail.example.com

When a recursive resolver queries the authoritative server for a domain name, the authoritative server returns the final record based on the zone data it manages, or returns a corresponding negative result.

6. DNS Role Relationships

Role Primary Responsibility Typically Stores Final Domain Records
Stub Resolver Initiates DNS queries May have a local cache
Recursive Resolver Completes resolution on behalf of the client Stores cache
Root Server Directs queries to the top-level domain Stores root zone delegation information
TLD Server Directs queries to the authoritative server Stores domain delegation information
Authoritative Server Provides the official records for the zone Yes

IV. What Happens After Entering a URL?

This is the most important scenario for understanding DNS.

Suppose the user enters the following in the browser:

https://www.example.com/products

The browser needs to find the server address corresponding to www.example.com before it can proceed to establish a network connection.

But in practice, the process does not start by querying from the root DNS server every time.

Multiple layers, such as the browser, the operating system, and the recursive resolver, may all cache DNS results.

1. Overall Process of a Browser Visiting a Website

The simplified process is as follows:

flowchart TD
    A["User enters URL"] --> B["Browser parses URL"]
    B --> C["Extract hostname www.example.com"]
    C --> D["Check browser DNS cache"]
    D --> E{"Is there a valid cache entry?"}
    E -->|Yes| F["Obtain target IP address"]
    E -->|No| G["Call OS resolver interface"]
    G --> H["Check system DNS cache"]
    H --> I{"Is there a valid cache entry?"}
    I -->|Yes| F
    I -->|No| J["Send query to recursive DNS resolver"]
    J --> K["Recursive resolver checks cache"]
    K --> L{"Is there a cache hit?"}
    L -->|Yes| M["Return DNS result"]
    L -->|No| N["Perform DNS hierarchical query"]
    N --> O["Return resolution result"]
    M --> P["Browser obtains IP address"]
    O --> P
    F --> Q["Continue establishing network connection"]
    P --> Q

    style A fill:#E0F0FE,stroke:#93BCE8,color:#1E4976
    style B fill:#F6FAF7,stroke:#DCE9E0,color:#334155
    style C fill:#F6FAF7,stroke:#DCE9E0,color:#334155
    style D fill:#E9E2F8,stroke:#B9A5DF,color:#514078
    style E fill:#FFF2CC,stroke:#E6C978,color:#765A18
    style F fill:#DCEFE5,stroke:#8EBFA5,color:#24563F
    style G fill:#F6FAF7,stroke:#DCE9E0,color:#334155
    style H fill:#E9E2F8,stroke:#B9A5DF,color:#514078
    style I fill:#FFF2CC,stroke:#E6C978,color:#765A18
    style J fill:#E0F0FE,stroke:#93BCE8,color:#1E4976
    style K fill:#E9E2F8,stroke:#B9A5DF,color:#514078
    style L fill:#FFF2CC,stroke:#E6C978,color:#765A18
    style M fill:#DCEFE5,stroke:#8EBFA5,color:#24563F
    style N fill:#E0F0FE,stroke:#93BCE8,color:#1E4976
    style O fill:#DCEFE5,stroke:#8EBFA5,color:#24563F
    style P fill:#DCEFE5,stroke:#8EBFA5,color:#24563F
    style Q fill:#FFF2CC,stroke:#E6C978,color:#765A18

Note: The diagram above is an abstract model of a typical resolution path. Different browsers, operating systems, and network configurations may adjust cache levels and resolution methods.

2. Step 1: Browser parses the URL

The browser first parses the URL entered by the user.

For example:

https://www.example.com:443/products?id=100#detail

It can be broken down as follows:

Part Content Meaning
Scheme https Uses HTTPS
Host www.example.com Target hostname
Port 443 Target port
Path /products Request path
Query id=100 Query parameters
Fragment detail Page fragment identifier

DNS mainly focuses on the Host:

www.example.com

It is not responsible for resolving /products, nor for handling URL query parameters.

3. Step 2: Check browser cache

Browsers may store domain names and IP addresses that have been resolved previously.

If the cache record is still valid, the cached result can be used directly.

For example:

www.example.com -> 93.184.216.34

This can reduce the number of DNS queries and lower access latency.

Different browsers do not have exactly the same caching policies, cache durations, and refresh mechanisms.

4. Step 3: Check operating system DNS cache

If there is a browser cache miss, the name resolution interface provided by the operating system is usually called.

The operating system may provide caching through the following mechanisms:

  • Local DNS cache service.
  • System name resolution daemon.
  • NSS name resolution module.
  • Local hosts file.

For example, on Linux:

cat /etc/hosts

It might contain:

127.0.0.1 localhost
192.168.1.100 internal.example.com

If the target domain name is explicitly mapped in the local hosts file, the system may return that address directly without sending a query to a DNS server.

On Windows, you can view it with:

ipconfig /displaydns

5. Step 4: Send a Query to a Recursive DNS Resolver

If no result can be obtained locally, the system sends the query to the configured DNS resolver.

For example:

Query domain: www.example.com
Query type: A

DNS requests are usually sent via UDP port 53.

After receiving the request, the recursive resolver first checks its own cache.

If a valid record already exists in the cache, it returns the result directly.

If there is no cached record, it begins querying other DNS servers.


V. DNS Recursive Queries and Iterative Queries

DNS query methods mainly involve recursive queries and iterative queries.

Understanding these two concepts is key to understanding how DNS works.

1. What Is a Recursive Query?

A recursive query means:

The client makes a request to a DNS resolver, expecting it to complete the resolution and return the final result or an error.

For example:

Client:
Please tell me the IP address of www.example.com.

Recursive resolver:
I’ll handle the lookup and return the final result to you.

The client does not need to visit the root servers, TLD servers, and authoritative servers level by level itself.

2. What Is an Iterative Query?

An iterative query means:

If a DNS server does not know the final answer, it can return information about the server that should be queried next.

For example:

Recursive resolver:
Root server, please tell me the address of www.example.com.

Root server:
I don't know the final address, but the .com DNS server is here.

Recursive resolver:
.com server, please tell me the address of example.com.

.com server:
I don't know the final address, but the authoritative server for example.com is here.

Recursive resolver:
Authoritative server, please tell me the address of www.example.com.

Authoritative server:
The IP address for www.example.com is 93.184.216.34.

The text here is only used to illustrate the interaction; actual queries and responses are completed through DNS messages.

3. Differences Between Recursive and Iterative Queries

Aspect Recursive Query Iterative Query
Expected by requester Final result Information the current server can provide
Responsibility of responder Continue completing resolution Return an answer or a clue for the next step
Typical scenario Client queries a recursive resolver Recursive resolver queries the DNS hierarchy
Query complexity Simple for the client Requires the requester to continue querying

In a typical DNS query process:

  • The client usually initiates a recursive query to the recursive resolver.
  • The recursive resolver usually queries the root, TLD, and authoritative servers iteratively.

4. Complete Recursive DNS Resolution Process

flowchart TD
    A["Client requests www.example.com"] --> B["Recursive resolver"]
    B --> C{"Recursive cache hit?"}
    C -->|Yes| D["Return cached result directly"]
    C -->|No| E["Query a root DNS server"]
    E --> F["Obtain .com TLD server information"]
    F --> G["Query a .com TLD server"]
    G --> H["Obtain example.com authoritative server information"]
    H --> I["Query an authoritative DNS server"]
    I --> J{"Target record found?"}
    J -->|Yes| K["Return an A or AAAA record"]
    J -->|No| L["Return a negative result or other response"]
    K --> M["Recursive resolver caches result"]
    L --> N["Cache negative result according to rules"]
    M --> O["Return to client"]
    N --> O
    D --> O

    style A fill:#E0F0FE,stroke:#93BCE8,color:#1E4976
    style B fill:#E9E2F8,stroke:#B9A5DF,color:#514078
    style C fill:#FFF2CC,stroke:#E6C978,color:#765A18
    style D fill:#DCEFE5,stroke:#8EBFA5,color:#24563F
    style E fill:#E0F0FE,stroke:#93BCE8,color:#1E4976
    style F fill:#DCEFE5,stroke:#8EBFA5,color:#24563F
    style G fill:#E0F0FE,stroke:#93BCE8,color:#1E4976
    style H fill:#DCEFE5,stroke:#8EBFA5,color:#24563F
    style I fill:#E0F0FE,stroke:#93BCE8,color:#1E4976
    style J fill:#FFF2CC,stroke:#E6C978,color:#765A18
    style K fill:#DCEFE5,stroke:#8EBFA5,color:#24563F
    style L fill:#F6FAF7,stroke:#DCE9E0,color:#334155
    style M fill:#DCEFE5,stroke:#8EBFA5,color:#24563F
    style N fill:#F6FAF7,stroke:#DCE9E0,color:#334155
    style O fill:#DCEFE5,stroke:#8EBFA5,color:#24563F

Actual DNS queries may have the following variations:

  • The root server query result is already cached, so the root server does not need to be queried again.
  • The TLD delegation information is already cached, so the authoritative server can be queried directly.
  • The authoritative server returns a CNAME, and the alias target must continue to be resolved.
  • The authoritative server returns multiple A or AAAA records.
  • The query fails or times out, and other servers need to be retried.
  • DNSSEC validation fails, and the resolver may refuse to return unvalidated results.

Therefore, not every visit to a website performs the complete three-level query of root, TLD, and authoritative servers.


VI. DNS Resource Records: What Exactly Does a Domain Name Store?

DNS uses Resource Records, abbreviated as RR, to store various kinds of information associated with domain names.

Each record usually contains:

Field Meaning
Name The domain name the record belongs to
Type Record type
Class Record class; on the Internet this is usually IN
TTL Cache time-to-live
RDATA Actual record data

For example:

www.example.com.  300  IN  A  93.184.216.34

Meaning:

  • Domain name: www.example.com
  • TTL: 300 seconds
  • Class: IN
  • Type: A
  • Data: 93.184.216.34

1. A Records

An A Record maps a domain name to an IPv4 address.

Example:

www.example.com.  300  IN  A  93.184.216.34

Query:

dig A www.example.com

2. AAAA Records

An AAAA Record maps a domain name to an IPv6 address.

Example:

www.example.com.  300  IN  AAAA  2001:db8::100

Query:

dig AAAA www.example.com

Note: 2001:db8::/32 is a documentation example address block, not a real public server address.

3. CNAME Records

CNAME, Canonical Name, a canonical name record, is used to point one domain name to another domain name.

For example:

www.example.com.  300  IN  CNAME  example.com.
example.com.      300  IN  A      93.184.216.34

The lookup process:

查询 www.example.com
    获得 CNAME:example.com
    继续查询 example.com
    获得 A:93.184.216.34

Characteristics of CNAME:

  • It points to another domain name, not to an IP address.
  • It can be used for domain name alias management.
  • The resolver needs to continue querying the target domain name.
  • A single DNS name cannot have both a CNAME and other ordinary data records at the same time.

Note in particular: the Zone Apex, that is, the apex of the zone, such as example.com, generally cannot be configured directly with an ordinary CNAME, because the zone apex must contain necessary records such as SOA and NS.

Some DNS providers offer extension mechanisms such as ALIAS, ANAME, or CNAME Flattening to solve the problem of pointing the root domain to another domain name, but these are not standard DNS CNAME records.

4. MX records

MX Record, Mail Exchange Record, is used to specify the mail receiving servers for a domain name.

Example:

example.com.  300  IN  MX  10 mail.example.com.

Here 10 is the priority; a smaller value generally means higher priority.

Query:

dig MX example.com

5. NS records

NS Record, Name Server Record, is used to specify the authoritative name servers for a DNS zone.

For example:

example.com.  3600  IN  NS  ns1.example.net.
example.com.  3600  IN  NS  ns2.example.net.

Query:

dig NS example.com

NS records are an important part of DNS zone delegation.

6. TXT records

TXT Record is used to store text information.

Common uses:

  • Domain ownership verification.
  • SPF mail sending policies.
  • DKIM public key information.
  • DMARC mail authentication policies.
  • Third-party service verification.

For example:

example.com.  300  IN  TXT  "site-verification=abc123"

Query:

dig TXT example.com

TXT records do not mean that a single piece of text of arbitrary length can be stored. The actual record format and length must follow DNS specifications and provider limits.

7. PTR records

PTR Record is used for reverse DNS resolution.

Forward resolution:

www.example.com -> 93.184.216.34

Reverse resolution:

93.184.216.34 -> example.com

IPv4 reverse resolution uses:

in-addr.arpa

IPv6 reverse resolution uses:

ip6.arpa

Query:

dig -x 8.8.8.8

Note that a PTR record does not guarantee that the returned domain name will necessarily match the forward resolution result, nor does it mean that the identity of the target server has been verified as trustworthy.

8. SRV records

SRV Record is used to describe the location of a specific service.

Commonly seen in:

  • LDAP.
  • SIP.
  • Some instant messaging systems.
  • Enterprise internal service discovery.

Example:

_service._tcp.example.com.  300  IN  SRV  10 5 443 service.example.com.

Where:

Field Example Meaning
Priority 10 Priority
Weight 5 Weight among records of the same priority
Port 443 Service port
Target service.example.com Target host of the service

9. SOA records

SOA, Start of Authority, is the starting authorization record of a DNS zone.

It contains information related to zone management and synchronization, for example:

  • Primary authoritative server name.
  • Domain-name form of the administrator's email address.
  • Serial: Zone version number.
  • Refresh: Secondary server refresh interval.
  • Retry: Retry interval after a refresh failure.
  • Expire: Maximum validity period of zone data.
  • Minimum: A legacy field related to negative caching; modern negative-caching TTLs are also subject to SOA parameter rules.

Query:

dig SOA example.com

10. Summary of Common DNS Records

Record Type Primary Purpose Data Content
A IPv4 address mapping IPv4 address
AAAA IPv6 address mapping IPv6 address
CNAME Domain name alias Target domain name
MX Mail server Priority and mail server
NS Authoritative server DNS server domain name
TXT Text information Text data
PTR Reverse resolution Target domain name
SRV Service discovery Priority, weight, port, and target
SOA Zone management Zone authority and synchronization information

VII. DNS Caching: Why Do DNS Changes Sometimes Not Take Effect?

DNS caching is an important mechanism for improving resolution performance.

If every visit to a website required starting the query from a root server, latency would be high and it would also generate a large number of DNS requests.

Therefore, the DNS system sets up caches at multiple levels.

1. Levels of DNS Caching

Common cache locations include:

  1. Browser DNS cache.
  2. Operating system DNS cache.
  3. Local DNS forwarder cache.
  4. Recursive DNS resolver cache.
  5. Caches on some network devices and in applications themselves.

For example:

Browser
  Stores domain name resolution results

Operating system
  Stores system resolution results

Recursive resolver
  Stores DNS query results

Authoritative DNS
  Provides official zone data

The existence of caches can reduce the number of queries, but it also causes delays in propagating DNS record updates.

2. What Is TTL?

TTL, Time To Live, indicates how long a DNS record can be cached.

For example:

www.example.com.  300  IN  A  93.184.216.34

A TTL of 300 seconds means that, subject to DNS caching rules, the record can be cached for 300 seconds.

As the cache time gradually decreases:

Initial TTL: 300 seconds
After 100 seconds: 200 seconds
After 200 seconds: 100 seconds
After 300 seconds: expired

After the cache expires, the resolver needs to obtain the record again.

3. TTL and When DNS Changes Take Effect

Suppose a domain name originally points to:

www.example.com -> 192.0.2.10

The administrator changes it to:

www.example.com -> 192.0.2.20

If a recursive resolver has previously cached the old record, clients may still receive the old IP.

Only after the old cache expires and the resolver queries the authoritative server again can it possibly obtain the new record.

Therefore:

Modifying an authoritative DNS record does not mean that all clients worldwide will immediately receive the new result.

4. TTL Configuration Strategies

Different scenarios can use different TTLs.

Scenario Common TTL Strategy Description
Stable business domain names Longer Reduce query load
Frequently changing service addresses Shorter Speed up propagation of changes
Planned server migration Lower in advance Reduce the impact of old caches during the switchover
CDN domain names According to provider policy Usually combined with scheduling and caching policies

Shorter TTLs are not always better.

A TTL that is too short may cause:

  • An increased number of DNS queries.
  • Increased load on recursive resolvers.
  • Increased query pressure on authoritative servers.
  • Increased client resolution latency.

A TTL that is too long may cause:

  • Slower propagation of address changes.
  • Failover to be affected by old caches.
  • Clients to still access the old address during server migration.

5. What Is Negative Caching?

Negative Caching refers to caching the results of DNS queries that fail or do not exist.

For example:

Nonexistent domain:
not-exist.example.com

The authoritative server may return:

NXDOMAIN

A recursive resolver can cache this result for a certain period of time, avoiding repeated queries for a nonexistent domain name.

Common negative responses:

Response Meaning
NXDOMAIN The queried domain does not exist
NODATA The domain exists, but there is no record corresponding to the requested type

Therefore, even if the administrator later creates a DNS record, the client may still see the old query failure result while the negative cache is valid.

6. How do you clear the DNS cache?

Windows:

ipconfig /flushdns

View the cache:

ipconfig /displaydns

On Linux with systemd-resolved:

sudo resolvectl flush-caches

View status:

resolvectl statistics

macOS:

sudo dscacheutil -flushcache
sudo killall -HUP mDNSResponder

Different Linux distributions may use different caching components. Clearing the system cache is not the same as clearing the browser cache or the cache of a public recursive DNS resolver.


8. Does DNS use UDP or TCP?

DNS primarily uses UDP port 53 and also supports TCP port 53.

1. Why does DNS usually use UDP?

Traditional DNS queries usually have the following characteristics:

  • Request data is relatively small.
  • Response data is usually relatively small.
  • One request usually corresponds to one response.
  • There is no need to establish a connection first, as with TCP.

UDP is connectionless and has low overhead, making it suitable for traditional DNS queries.

Typical communication:

Client UDP port
       |
       | DNS Query
       v
DNS server UDP 53
       |
       | DNS Response
       v
Client

Note that UDP does not guarantee reliable transmission; the DNS client or resolver must handle timeouts, retries, and selection of alternate servers itself.

2. Why does DNS also need TCP?

DNS uses TCP mainly in the following scenarios:

  • Response data is relatively large.
  • The UDP response is truncated.
  • DNS zone transfers.
  • Some DNS services or network environments require TCP.

For example, when a traditional UDP DNS response exceeds the available message size, the server may set the TC flag to indicate that the response has been truncated.

The client will usually retry the query over TCP.

3. Basic flow of DNS over TCP

flowchart TD
    A["Client initiates DNS query"] --> B["Send query via UDP"]
    B --> C["DNS server returns response"]
    C --> D{"Is it truncated?"}
    D -->|No| E["Use UDP response result"]
    D -->|Yes| F["Establish TCP connection"]
    F --> G["Resend DNS query over TCP"]
    G --> H["DNS server returns full response"]
    H --> I["Client obtains result"]

    style A fill:#E0F0FE,stroke:#93BCE8,color:#1E4976
    style B fill:#F6FAF7,stroke:#DCE9E0,color:#334155
    style C fill:#F6FAF7,stroke:#DCE9E0,color:#334155
    style D fill:#FFF2CC,stroke:#E6C978,color:#765A18
    style E fill:#DCEFE5,stroke:#8EBFA5,color:#24563F
    style F fill:#E9E2F8,stroke:#B9A5DF,color:#514078
    style G fill:#F6FAF7,stroke:#DCE9E0,color:#334155
    style H fill:#DCEFE5,stroke:#8EBFA5,color:#24563F
    style I fill:#DCEFE5,stroke:#8EBFA5,color:#24563F

4. What is EDNS?

EDNS, which stands for Extension Mechanisms for DNS, is an extension mechanism for DNS.

The UDP payload size of traditional DNS messages is limited by the early protocol design.

EDNS allows clients and servers to negotiate larger UDP DNS message capabilities and supports additional extension information.

The functions of EDNS include:

  • Extending the UDP DNS message size.
  • Supporting negotiation of DNSSEC-related capabilities.
  • Carrying certain extension options.
  • Supporting extension information such as ECS.

EDNS is not an independent transport protocol; it is an extension to the DNS protocol.

5. DNS port summary

Protocol Port Primary Use
UDP 53 Common DNS queries
TCP 53 Large responses, zone transfers, etc.
HTTPS 443 DNS over HTTPS
TLS 853 DNS over TLS

9. DNS Security: Why Can DNS Be Attacked?

DNS is Internet infrastructure, so it can also become an important target for attackers.

Common issues include DNS spoofing, cache poisoning, domain hijacking, and amplification attacks.

1. DNS Spoofing: DNS Spoofing

DNS spoofing means an attacker forges DNS responses so users receive incorrect IP addresses.

For example:

Normal resolution:
bank.example -> legitimate server IP

After spoofing:
bank.example -> attacker-controlled IP

The domain name entered by the user does not change, but the browser may connect to the wrong server.

This can cause:

  • Visits to phishing websites.
  • Leakage of user credentials.
  • Malware propagation.
  • Traffic being directed to attacker-controlled infrastructure.

2. DNS Cache Poisoning: Cache Poisoning

DNS cache poisoning means an attacker tries to make a recursive resolver cache forged DNS data.

If the forged result is accepted, subsequent users querying the same domain may all receive incorrect results.

Defenses include:

  • Use a trustworthy recursive resolver.
  • Enable DNSSEC validation.
  • Use sufficiently random query source ports.
  • Use randomized query IDs.
  • Restrict untrusted DNS responses.
  • Keep DNS software updated.

3. DNS Hijacking: DNS Hijacking

DNS hijacking means an attacker or malware modifies the DNS query path.

Common methods include:

  • Modify the local DNS server configuration.
  • Tamper with router DNS configuration.
  • Control recursive DNS services.
  • Use malware to modify system resolution settings.
  • Direct DNS traffic through network device policies.

When troubleshooting, check:

cat /etc/resolv.conf

Windows:

Get-DnsClientServerAddress

4. DNS Amplification: DNS Amplification Attack

A DNS amplification attack is a reflective DDoS attack.

Attackers use DNS requests with forged source IPs to make DNS servers send large amounts of response data to victims.

Typical characteristics:

  • Request data is relatively small.
  • Response data may be relatively large.
  • The victim receives a large number of unsolicited responses.
  • Multiple open recursive resolvers may be abused.

Defenses:

  • Limit the scope of recursive queries.
  • Avoid exposing open recursive resolvers to the entire Internet.
  • Use response rate limiting.
  • Deploy DDoS protection.
  • Adopt network-side measures such as source address validation.

5. DNSSEC: DNS Security Extensions

DNSSEC, short for Domain Name System Security Extensions, is a DNS security extension mechanism.

It uses digital signatures to verify the authenticity and integrity of DNS data.

Core goals of DNSSEC:

  • Verify the origin of DNS data.
  • Check whether DNS data has been tampered with.
  • Establish a chain of trust between DNS zones.

DNSSEC mainly involves the following records:

Record Purpose
DNSKEY Stores the zone public key
RRSIG Digitally signs resource record sets
DS Establishes a trust association from parent zone to child zone
NSEC Proves that certain names or records do not exist
NSEC3 Provides hashed denial-of-existence proofs

The DNSSEC validation chain is usually established starting from the root zone and validated step by step through records such as DS and DNSKEY.

flowchart TD
    A["Root zone trust anchor"] --> B["Verify root zone signature"]
    B --> C["Verify TLD DS record"]
    C --> D["Verify TLD DNSKEY"]
    D --> E["Verify child zone DS record"]
    E --> F["Verify child zone DNSKEY"]
    F --> G["Verify target resource record RRSIG"]
    G --> H{"Signature verification successful?"}
    H -->|Yes| I["Return verified data"]
    H -->|No| J["Mark validation as failed and reject the result as trusted"]

    style A fill:#E0F0FE,stroke:#93BCE8,color:#1E4976
    style B fill:#DCEFE5,stroke:#8EBFA5,color:#24563F
    style C fill:#E0F0FE,stroke:#93BCE8,color:#1E4976
    style D fill:#DCEFE5,stroke:#8EBFA5,color:#24563F
    style E fill:#E0F0FE,stroke:#93BCE8,color:#1E4976
    style F fill:#DCEFE5,stroke:#8EBFA5,color:#24563F
    style G fill:#E9E2F8,stroke:#B9A5DF,color:#514078
    style H fill:#FFF2CC,stroke:#E6C978,color:#765A18
    style I fill:#DCEFE5,stroke:#8EBFA5,color:#24563F
    style J fill:#F6FAF7,stroke:#DCE9E0,color:#334155

DNSSEC requires particular attention:

  • DNSSEC is not responsible for encrypting DNS query content.
  • DNSSEC does not hide the domain names users visit.
  • DNSSEC is not the same as HTTPS.
  • DNSSEC cannot prevent all attacks at the DNS level.
  • The effectiveness of DNSSEC depends on the correct configuration of signatures, keys, and the chain of trust.

6. DoH and DoT: Encrypted DNS Queries

DNSSEC mainly verifies the authenticity of DNS data, whereas DoH and DoT mainly address privacy and integrity issues during the transmission of DNS queries.

DNS over HTTPS

DoH, DNS over HTTPS, encapsulates DNS queries within HTTPS for transmission.

Characteristics:

  • Typically uses TCP port 443.
  • Can reuse existing HTTPS infrastructure.
  • DNS query content is protected by TLS during transmission.
  • Can reduce opportunities for intermediary network devices to directly read DNS query content.

DNS over TLS

DoT, DNS over TLS, uses TLS to encrypt DNS queries.

Typically uses TCP port 853.

Characteristics:

  • DNS data is transmitted encrypted via TLS.
  • Can protect query content between the client and the recursive resolver.
  • Is clearly different from traditional UDP DNS.

Comparison of DoH, DoT, and DNSSEC

Technology Primary Goal Encrypts Query Content
Traditional DNS Domain name resolution Usually not encrypted
DNSSEC Verify authenticity of DNS data No
DoH Encrypt DNS transmission Yes
DoT Encrypt DNS transmission Yes

Note: DoH and DoT mainly protect the transmission between the client and the recursive resolver; they do not mean that every segment of the entire DNS resolution path automatically gains end-to-end encryption.


X. DNS and Browser Access: What Else Happens After Resolution Completes?

DNS is only responsible for helping the client find the target IP address.

Once the IP is obtained, the browser still needs to carry out the subsequent network communication process.

Take a visit to:

https://www.example.com

as an example.

1. The Network Flow After DNS Resolution

flowchart TD
    A["User enters HTTPS URL"] --> B["Resolve domain name"]
    B --> C["Obtain target IP address"]
    C --> D["Determine target network location"]
    D --> E["Obtain next-hop MAC address"]
    E --> F["Send network data packet"]
    F --> G["Routers forward hop by hop"]
    G --> H["Reach target server network"]
    H --> I["Establish TCP connection"]
    I --> J["Perform TLS handshake"]
    J --> K["Verify server certificate"]
    K --> L{"Are certificate and handshake valid?"}
    L -->|Yes| M["Send HTTP request"]
    L -->|No| N["Connection fails or triggers security warning"]
    M --> O["Server processes request"]
    O --> P["Return HTTP response"]
    P --> Q["Browser parses and renders page"]

    style A fill:#E0F0FE,stroke:#93BCE8,color:#1E4976
    style B fill:#E9E2F8,stroke:#B9A5DF,color:#514078
    style C fill:#DCEFE5,stroke:#8EBFA5,color:#24563F
    style D fill:#FFF2CC,stroke:#E6C978,color:#765A18
    style E fill:#F6FAF7,stroke:#DCE9E0,color:#334155
    style F fill:#F6FAF7,stroke:#DCE9E0,color:#334155
    style G fill:#F6FAF7,stroke:#DCE9E0,color:#334155
    style H fill:#DCEFE5,stroke:#8EBFA5,color:#24563F
    style I fill:#E0F0FE,stroke:#93BCE8,color:#1E4976
    style J fill:#E9E2F8,stroke:#B9A5DF,color:#514078
    style K fill:#E9E2F8,stroke:#B9A5DF,color:#514078
    style L fill:#FFF2CC,stroke:#E6C978,color:#765A18
    style M fill:#DCEFE5,stroke:#8EBFA5,color:#24563F
    style N fill:#F6FAF7,stroke:#DCE9E0,color:#334155
    style O fill:#F6FAF7,stroke:#DCE9E0,color:#334155
    style P fill:#DCEFE5,stroke:#8EBFA5,color:#24563F
    style Q fill:#DCEFE5,stroke:#8EBFA5,color:#24563F