Dns Ip Addresses And Tcp Connections
Post 2 fired a request at a URL and got country data back. This is what actually happens in the gap between those two moments, before a single byte of HTTP is sent.
Last post fired a request at https://countries-api-836d.onrender.com/countries/name/portugal and got country data back. That URL isn't the real address of anything, and there's a whole handshake that happens before your request even leaves for the actual server.
Think of it like mailing a letter. You don't write "Countries API" on an envelope and expect a mail carrier to know where that is, you need an actual street address first. Everything in this post is what happens to find that address and get a direct line open, before you've written a single word of the actual letter.
A Domain Name Isn't a Real Address
countries-api-836d.onrender.com is a name, not an address. It's easy to remember and type, which is exactly why it exists, but no computer on the internet actually lives at "a name." Somewhere, that name has to get translated into a real, numeric address a server actually answers to.
That translation happens through a DNS lookup, DNS standing for Domain Name System. It works like a directory: your browser hands over the name, and DNS hands back the one thing that name actually maps to, an IP address, a plain number like 216.24.57.1 that points at one specific machine.
This lookup is the very first thing that happens when you access any URL, before anything else, and it usually happens through your internet provider without you ever seeing it. You can watch it happen yourself: open a terminal and run nslookup countries-api-836d.onrender.com. Ignore the Server line at the top, that's just your own computer's DNS resolver answering you. The real answer is further down, under Name and Addresses, that's the actual IP DNS resolved this domain to.
The Real Address Includes a Port
Once DNS hands back an IP address, that's still not quite the full picture. The real destination is written as IP address plus a port number, something like 216.24.57.1:443.
If the IP address is the building, the port is the specific suite number inside it. A single server can run several different services at once (a website, an email service, whatever else), and the port is what tells the connection which one of those you actually want to talk to. It has nothing to do with the /countries/name/portugal part of the URL, that gets sent later, as part of the actual message.
Opening a Connection Before Saying Anything
With a real address in hand, the browser and the server open what's called a TCP socket connection. This is the equivalent of actually getting a line open between you and the destination before you say a word, a dedicated channel that both sides keep alive for as long as data needs to move back and forth.
Only once that connection exists does it make sense to send anything over it. What the actual message looks like once there's a real, open line to send it on is next.
ExpandFrom a domain name to an open connection: DNS translates the name into a real IP address, the port picks a specific service at that address, and a TCP connection stays open for the transfer.
What TCP and IP Are Actually For
TCP and IP are the two protocols, meaning agreed-upon rulebooks, that make this whole exchange possible. Between them, they answer two separate questions: how does data get routed to the right place, and how does it arrive in one piece.
IP handles the first question. Every packet of data gets stamped with the destination IP address, the same way every parcel in a shipping network gets a destination label, so it can be routed correctly regardless of which physical path it actually takes.
TCP handles the second. Instead of sending an entire request or response as one enormous chunk, TCP breaks it into thousands of small packets first. Picture shipping a large order as a stack of small parcels sent out separately rather than one oversized crate, each parcel can take a different route and travel in parallel, which gets the whole shipment there far faster than moving one giant block through the same congested path. Once the packets arrive, TCP is also the one that reassembles them back into the original message, in the right order, checking that nothing got lost along the way.
That's the entire job of this layer: get a real address, open a line, and have a reliable way to move data across it in pieces. What actually rides across that connection, the request and the response themselves, is next.
The Essentials
- A domain name is not a real address. A DNS lookup translates it into the actual numeric IP address of the server, the same way a directory turns a name into a street address.
- The real destination is an IP address plus a port, the IP picks the building, the port picks the specific service running inside it.
- A TCP socket connection has to open before any data is sent, a direct channel between browser and server that stays alive for the length of the transfer.
- IP's job is routing: stamping every packet with a destination so it gets to the right place regardless of the path it takes.
- TCP's job is reliability: breaking a request or response into many small packets so they can travel in parallel, then reassembling them correctly at the other end.
Keep reading