What Happens When You Hit Enter on a URL? Deep Dive into DNS, TCP, HTTP
When you type a URL and press Enter, the browser performs a series of steps—including URL parsing, DNS resolution across multiple caches, TCP three‑way handshake, HTTP request construction, server processing, and response handling—each involving specific protocols and layers that together deliver the requested web page.
"When you press Enter after typing a URL, have you ever wondered what actually happens?" This question is often used in technical interviews because it touches many underlying principles of networking, operating systems, and web technologies.
Note: The following steps assume a simple HTTP request without HTTPS, HTTP/2, advanced DNS features, proxies, or server errors. The scenario is idealized for educational purposes.
Article Flow
URL Parsing → DNS Query → TCP Connection → Request Handling → Response Reception
Address Parsing
The browser first determines whether the input is a valid URL or a search keyword, then performs auto‑completion, character encoding, and other preprocessing.
DNS Query
The DNS resolution process involves several layers of caching:
Browser cache: The browser checks its own cache first.
Operating system cache: If not found, the OS checks its DNS cache and the local hosts file before querying a DNS server.
Router cache: The local router may have cached entries.
ISP DNS cache: The ISP’s recursive resolver often stores recent lookups.
If none of the caches contain the answer, the request reaches the root name servers, which delegate the query down the DNS hierarchy. The following diagram illustrates the full DNS lookup flow:
TCP Connection
TCP/IP is divided into four layers. When sending data, each layer adds its own header (encapsulation). The application layer constructs the HTTP request, the transport layer establishes a TCP connection using a three‑way handshake, the network layer adds IP addresses and determines routing, and the link layer frames the data for Ethernet transmission.
Application Layer: Sending HTTP Request
Request header (method, target URL, protocol version, etc.)
Request body (optional parameters)
Browsers typically use the GET method for loading web pages.
Transport Layer: TCP Segments
The transport layer splits data into segments, numbers them, and ensures reliable delivery. Before data transfer, a three‑way handshake establishes the connection.
Network Layer: IP Routing and ARP
IP packets are wrapped with source and destination IP addresses. If the destination is on the same subnet, the packet is sent directly using the MAC address; otherwise, routing tables and ARP are used to find the next hop.
Link Layer: Ethernet Frames
Ethernet frames consist of a header (source/destination MAC, type) and the payload. MAC addresses are unique identifiers for network interfaces. Broadcast frames are sent to all devices on the local network, while unicast frames target a specific MAC.
Server Processing
On the server side, a web server (e.g., Apache, Nginx, IIS) listens for incoming TCP connections, spawns a worker process, parses the HTTP request, and performs validation such as virtual‑host configuration, method allowance, and access control.
If a redirect is configured, the server returns a 301 response, prompting the browser to repeat the request. URL rewriting rules may map the request to a static file or a dynamic route handled by a framework (e.g., PHP MVC).
Browser Receiving Response
After the server sends the response, the browser examines the response headers, handles status codes (including redirects), decompresses the payload if necessary (e.g., gzip), caches the resource, and parses the content based on its MIME type (HTML, image, etc.).
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Open Source Linux
Focused on sharing Linux/Unix content, covering fundamentals, system development, network programming, automation/operations, cloud computing, and related professional knowledge.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
