34 34. URLs, Domain Names, IP Addresses, and DNS
A web address tells the browser exactly what to fetch and from which server. This page takes web addresses apart, then follows the human-friendly name (like www.amazon.com) to the numeric address computers actually use - with the help of DNS, the Internet’s phone book.
34.1 Anatomy of a URL
A URL (Uniform Resource Locator) is the full address of something on the web. Here is one with all the common parts:
https://www.example.com:443/products/shoes?color=red&size=9#reviews
| Part | In the example | What it means |
|---|---|---|
| scheme | https:// |
How to talk to the server: here, HTTPS |
| domain name (host) | www.example.com |
Which server to contact |
| port | :443 |
Which program on that server. Usually left out: https means 443 and http means 80 |
| path | /products/shoes |
Which page or resource on that server (like a file path) |
| query string | ?color=red&size=9 |
Extra settings as name=value pairs, after a ? and separated by & |
| fragment | #reviews |
A spot within the page. The browser handles it; it is not sent to the server |
Now a real one, from Amazon’s toy department:
https://www.amazon.com/toys/b?ie=UTF8&node=165793011
The scheme is https://, the domain is www.amazon.com, the path is /toys/b, and the query string holds two parameters: ie=UTF8 and node=165793011 (an ID Amazon uses for the toys category). There is no port (so 443) and no fragment.
A few more things worth knowing:
- Other schemes exist. When you double-click an HTML file on your own computer, the address bar shows a
file:///...URL: the browser reads the file straight from your disk, with no server involved. - Development URLs have the same anatomy:
http://localhost:3000/events?club=chesshas a scheme, a host (localhost), a port (3000), a path and a query string. - Spaces and some other characters aren’t allowed in URLs, so they are encoded: a space becomes
%20(or+inside a query string).
34.1.1 Origins, and URI vs URL
The first three parts together, scheme + host + port, are called the URL’s origin. https://www.example.com:443/products/shoes and https://www.example.com/cart have the same origin (https://www.example.com, port 443 either way), so the browser treats them as the same website. Change any one of the three and it’s a different origin: http://localhost:3000 and http://localhost:5173 are two different sites to the browser, even though both run on your computer. Browsers keep cookies and logins separate per origin, and services such as Google’s sign-in ask you for the exact origins of your app.
You’ll also see the word URI (Uniform Resource Identifier), for example “Authorized redirect URIs” in Google Cloud. A URI is the wider idea: any string that identifies something. Every URL is a URI, but a URI can also be just a name that doesn’t tell you where to find the thing, such as urn:isbn:9780141036144 (a book’s ISBN). When a form asks for a URI and the example is a web address, it means a URL.
& and ? are special characters in the shell: & runs a command in the background and ? is a wildcard. When you paste a URL with a query string into a command, wrap it in quotes: curl "https://www.example.com/search?q=shoes&page=2". (See Single Quotes vs. Double Quotes and Wildcards and Pipes.)
34.2 Domain names
A domain name is a human-friendly name for a server (or a group of servers). Read it from right to left, from the most general part to the most specific:
www . amazon . com
| | |
subdomain the name top-level domain (TLD)
Amazon
registered
- The top-level domain (TLD) is the last part:
.com,.org,.edu,.gov, country codes such as.ukor.ca, and newer ones such as.appor.dev. - The name to its left, together with the TLD, is the domain someone registered (rented):
amazon.com. (Some countries add a level: inbbc.co.uk, the registered domain isbbc.co.uk.) - Anything further left is a subdomain, which the domain’s owner can create freely:
www.amazon.com,docs.github.com,mail.google.com.
Domain names are not case-sensitive: AMAZON.com and amazon.com are the same. (The path part of a URL can be case-sensitive, depending on the server.)
34.3 IP addresses
Computers don’t actually find each other by name. Every device on the Internet is reached through a numeric IP address (Internet Protocol address) - think of it as the computer’s phone number. There are two kinds:
- IPv4: four numbers from 0 to 255 separated by dots, such as
23.197.45.160. There are only about 4.3 billion of these - not enough for all the world’s devices - so the newer version was created. - IPv6: much longer, written in hexadecimal with colons, such as
2600:141b:1c00:27a3::3bd4(::is shorthand for a run of zeros).
Both are in use today. One special address you have already met is 127.0.0.1 (IPv6: ::1), which always means “this computer”.
34.3.1 localhost and 127.0.0.1
localhost is a name and 127.0.0.1 is its address: both mean “this computer”. It’s called the loopback address, because a request sent there never leaves your computer; it loops straight back. That’s why:
http://localhost:3000reaches the program listening on port 3000 on your own computer: a development server you started, for example.- Nobody else can open your
localhost:3000. On their computer, the same address means their computer. To show your app to others, you put it on a server with a real domain name (for example on Vercel). - Services treat it as a special case. Google’s sign-in, for example, accepts plain
http://only forlocalhost; every other address must usehttps://.
The name and the number lead to the same place, but they are different origins (see Origins, and URI vs URL): to a browser, http://localhost:3000 and http://127.0.0.1:3000 are two different sites, with separate cookies and logins. When a setup page lists http://localhost:3000, use exactly that.
Why have names at all? Names are easy to remember; the numbers behind a name can change (when a company moves to a new host) without anyone noticing; and one name can lead to many servers, just as one server can host many names.
34.4 DNS: the Internet’s phone book
DNS (the Domain Name System) translates domain names into IP addresses. When you type www.amazon.com and press Enter:
1. Browser: "What is the IP address of www.amazon.com?"
| (checks its own memory first)
v
2. DNS resolver (run by your Internet provider or campus network,
or a public one such as 1.1.1.1 or 8.8.8.8)
| asks other DNS servers if it doesn't already know
v
3. Answer: "www.amazon.com is at 23.197.45.160"
|
v
4. Browser connects to 23.197.45.160 and sends: GET / ...
Answers are remembered (cached) for a while at each step, so most lookups take a few milliseconds. The flip side: when a domain is pointed at a new server, some people may keep seeing the old one until the cached answers expire - from minutes to hours.
34.5 Try it: nslookup and ping
Both commands work in Mac Terminal and in Git Bash (on Windows they run Windows’ own versions).
34.5.1 nslookup: ask DNS directly
nslookup www.amazon.comOutput (shortened - your names and numbers will differ):
Server: 192.168.1.1
Address: 192.168.1.1#53
Non-authoritative answer:
www.amazon.com canonical name = tp.47cf2c8c9-frontier.amazon.com.
tp.47cf2c8c9-frontier.amazon.com canonical name = www.amazon.com.edgekey.net.
www.amazon.com.edgekey.net canonical name = e15316.dsca.akamaiedge.net.
Name: e15316.dsca.akamaiedge.net
Address: 23.197.45.160
...
Serveris the DNS resolver your computer asked.- “Non-authoritative answer” means the answer came from a resolver, not from Amazon’s own DNS servers.
- Each
canonical nameline is an alias:www.amazon.comis another name for a name that is another name for… a server run by Akamai, a CDN company (see the deeper dive in Browsers, Web Servers, and HTTP). Amazon uses more than one CDN, so your chain may end somewhere else - for example at a name starting withcf.and ending inamazon.com, which belongs to CloudFront, Amazon’s own CDN. Addresslines give the IP addresses (you may also see long IPv6 ones).
On Windows the same information appears in a different layout, with the aliases listed at the end.
34.5.2 ping: is that computer answering?
ping sends small “are you there?” messages to a computer and reports each reply and how long it took (in milliseconds). It also shows which IP address the name turned into. The Mac and Windows versions behave differently:
ping www.amazon.comMac’s ping keeps going until you press Ctrl+C. Output (yours will differ):
PING e15316.dsca.akamaiedge.net (23.197.45.160): 56 data bytes
64 bytes from 23.197.45.160: icmp_seq=0 ttl=55 time=12.104 ms
64 bytes from 23.197.45.160: icmp_seq=1 ttl=55 time=11.387 ms
64 bytes from 23.197.45.160: icmp_seq=2 ttl=55 time=13.020 ms
^C
--- e15316.dsca.akamaiedge.net ping statistics ---
3 packets transmitted, 3 packets received, 0.0% packet loss
round-trip min/avg/max/stddev = 11.387/12.170/13.020/0.669 ms
To send a fixed number of pings, use -c (count): ping -c 4 www.amazon.com.
ping www.amazon.comIn Git Bash, ping runs Windows’ own ping program, which sends 4 pings and stops by itself. Output (yours will differ):
Pinging e15316.dsca.akamaiedge.net [23.197.45.160] with 32 bytes of data:
Reply from 23.197.45.160: bytes=32 time=12ms TTL=55
Reply from 23.197.45.160: bytes=32 time=11ms TTL=55
Reply from 23.197.45.160: bytes=32 time=13ms TTL=55
Reply from 23.197.45.160: bytes=32 time=12ms TTL=55
Ping statistics for 23.197.45.160:
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 11ms, Maximum = 13ms, Average = 12ms
Use -n to choose how many: ping -n 10 www.amazon.com. Use -t to keep going until you press Ctrl+C.
Three things to notice:
- The name in the first line may differ from the one you typed - that is the alias chain from
nslookupat work. - Depending on your network you may see an IPv6 address instead of an IPv4 one.
- No reply (“Request timed out”) does not always mean a site is down: many servers are configured to ignore pings while still serving web pages.
34.6 Getting your own domain
You don’t buy a domain forever; you register (rent) it, usually a year at a time, from a registrar such as Namecheap, Porkbun, Cloudflare or GoDaddy (many hosting services sell domains too). Prices depend on the TLD, and you must keep renewing the registration or lose the domain.
You don’t need your own domain to get started: hosting services give you a free address on their domain, such as yourname.github.io or your-app.vercel.app - a subdomain they create for you. Connecting a domain you bought to your hosting service is covered in Hosting and Deployment.
A domain’s DNS settings are a short list of records. The common types:
| Type | Points a name to… | Typical use |
|---|---|---|
| A | an IPv4 address | example.com → 203.0.113.10 |
| AAAA | an IPv6 address | example.com → 2001:db8::10 |
| CNAME | another name (an alias) | www.example.com → my-site.hosting-provider.example |
| MX | the servers that receive email | where mail for @example.com goes |
| TXT | a piece of text | proving to a service that you own the domain |
(The addresses and names above are reserved for examples.) When a hosting service says “add a CNAME record for www pointing to …”, you log in to your registrar (or DNS provider), add that record, and wait for DNS caches to pick up the change. Each record also has a TTL (time to live): how many seconds resolvers may cache it.
Practice Questions
Easy
Question 1 · Short answer
Label the parts of this URL: scheme, domain name, path, query string and fragment.
https://shop.example.com/cart?item=42&qty=2#summary
Question 2 · Multiple choice
What does DNS do?
- Encrypts the connection between your browser and a server
- Translates domain names into IP addresses
- Stores the files of a website
- Sends “are you there?” messages to a computer
Question 3 · True or false
The fragment part of a URL (for example #reviews) is sent to the server along with the path.
Question 4 · Short answer
Which of these addresses is IPv4 and which is IPv6? 2001:db8::10 and 203.0.113.10.
Question 5 · Fill in the blank
In docs.github.com, the top-level domain is ______, the registered domain is ______, and ______ is a subdomain.
Question 6 · Short answer
What special IP address means “this computer”, and which name do you usually use for it?
Medium
Question 7 · Write the command
Write a command that sends exactly 4 pings to www.wikipedia.org, first for Maria (Mac) and then for Sam (Git Bash on Windows).
Question 8 · Predict
Maria (Mac) and Sam (Git Bash on Windows) both type ping www.amazon.com and then do nothing. What does each of them see after a minute?
Question 9 · Short answer
In the URL https://www.amazon.com/toys/b?ie=UTF8&node=165793011, list the query parameters as name/value pairs. Which part of the URL tells Amazon’s server which page you want?
Question 10 · Find the bug
Sam pastes this into Git Bash and gets strange results (the command seems to run “in the background” and the server complains that a parameter is missing):
curl https://www.example.com/search?q=shoes&page=2What went wrong, and how should he write it?
Question 11 · Scenario
A club moves its website to a new hosting service and updates its DNS records. An hour later, some members see the new site and others still see the old one. Why?
Question 12 · Multiple choice
Which of these is a subdomain of github.com?
github.iodocs.github.comgithub.com/docsmygithub.com
Question 13 · Short answer
Give two reasons why the web uses domain names instead of making people type IP addresses.
Question 14 · Compare
Which of these addresses have the same origin as http://localhost:3000/dashboard? Explain each answer.
http://localhost:3000/loginhttps://localhost:3000/dashboardhttp://localhost:5173/dashboardhttp://127.0.0.1:3000/dashboard
Question 15 · Short answer
You run a web app on your laptop and open http://localhost:3000. You send the same address to a friend, and on their laptop it doesn’t work (or shows something else). Why? What would you need to do so that your friend can use your app?
Hard
Question 16 · Scenario
ping www.example-store.com prints “Request timed out” for every attempt, but the site loads fine in your browser. Is the site down? Explain.
Question 17 · Scenario
nslookup www.amazon.com shows a chain of canonical name lines ending in e15316.dsca.akamaiedge.net. What does this tell you about how Amazon delivers its home page to you?
Question 18 · Long answer
Describe, step by step, what happens between typing https://www.example.com/about into the address bar and seeing the page. Use the terms DNS, IP address, HTTPS, request and response.
Question 19 · Scenario
You bought the domain myclubapp.com. Your hosting service tells you: “Add a CNAME record for www pointing to xyz.hosting-provider.example.” What will this record do, and where do you add it?
Question 20 · Compare
For http://localhost:3000/events?id=7#details, name each part. Which parts reach the development server, and which part never leaves the browser?
Question 21 · Long answer
Your club wants its own domain for its website. Explain to the club officers, in plain English, the difference between registering a domain and hosting a website, and why you need both (or neither, at first).
Question 22 · Scenario
A teammate claims: “Domain names are case-sensitive, so https://WWW.Example.com/About and https://www.example.com/about are definitely different pages.” Is that right? Explain.
Question 23 · Hands-on
Run nslookup for three sites you use (for example www.wikipedia.org, www.google.com and your school’s website). For each one, note: does it have canonical name (alias) lines? How many addresses come back? Do you see any IPv6 addresses? Then ping one of them a few times and compare the times with a friend on a different network.