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=chess has 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.

Put URLs in quotes on the command line

& 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 .uk or .ca, and newer ones such as .app or .dev.
  • The name to its left, together with the TLD, is the domain someone registered (rented): amazon.com. (Some countries add a level: in bbc.co.uk, the registered domain is bbc.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:3000 reaches 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 for localhost; every other address must use https://.

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.com

Output (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
...
  • Server is 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 name line is an alias: www.amazon.com is 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 with cf. and ending in amazon.com, which belongs to CloudFront, Amazon’s own CDN.
  • Address lines 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.com

Mac’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.com

In 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 nslookup at 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
  • scheme: https://
  • domain name: shop.example.com
  • path: /cart
  • query string: ?item=42&qty=2 (two parameters: item=42 and qty=2)
  • fragment: #summary

There is no port, so the default for HTTPS (443) is used.

Question 2 · Multiple choice

What does DNS do?

  1. Encrypts the connection between your browser and a server
  2. Translates domain names into IP addresses
  3. Stores the files of a website
  4. Sends “are you there?” messages to a computer

b. DNS works like a phone book: name in, IP address out. Encryption (a) is what HTTPS does, storing files (c) is the web server’s job, and (d) describes ping.

Question 3 · True or false

The fragment part of a URL (for example #reviews) is sent to the server along with the path.

False. The fragment stays in the browser, which uses it to jump to a spot within the page. The server only receives the path and the query string.

Question 4 · Short answer

Which of these addresses is IPv4 and which is IPv6? 2001:db8::10 and 203.0.113.10.

203.0.113.10 is IPv4 (four numbers from 0 to 255 separated by dots). 2001:db8::10 is IPv6 (hexadecimal groups separated by colons; :: stands for a run of zeros).

Question 5 · Fill in the blank

In docs.github.com, the top-level domain is ______, the registered domain is ______, and ______ is a subdomain.

The TLD is .com, the registered domain is github.com, and docs is a subdomain (so the full name docs.github.com is a subdomain of github.com).

Question 6 · Short answer

What special IP address means “this computer”, and which name do you usually use for it?

127.0.0.1 (or ::1 in IPv6). Its name is localhost.

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).

Maria (Mac):

ping -c 4 www.wikipedia.org

Sam (Git Bash, which runs Windows’ ping) - plain ping www.wikipedia.org already sends 4, or explicitly:

ping -n 4 www.wikipedia.org

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?

  • Maria: replies keep scrolling, one per second, because Mac’s ping runs until she presses Ctrl+C (then it prints a summary).
  • Sam: four replies and a summary, then his prompt is back - Windows’ ping stops after 4 by default.

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?

Two parameters: name ie with value UTF8, and name node with value 165793011. The path, /toys/b, tells the server which page; the query string adds settings (here, the category ID).

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=2

What went wrong, and how should he write it?

The shell treats & as “run the command before it in the background”, so the command is cut at the &: curl only receives https://www.example.com/search?q=shoes, and page=2 is treated as a separate shell command. (On a Mac with zsh, the ? can also cause a “no matches found” error, because ? is a wildcard.) Put the URL in quotes:

curl "https://www.example.com/search?q=shoes&page=2"

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?

DNS answers are cached by resolvers (and by browsers and operating systems) for a while - up to each record’s TTL. Members whose resolvers still hold the old answer are sent to the old server until that cached answer expires. Waiting (minutes to hours) fixes it.

Question 12 · Multiple choice

Which of these is a subdomain of github.com?

  1. github.io
  2. docs.github.com
  3. github.com/docs
  4. mygithub.com

b. docs is added to the left of github.com. github.io (a) and mygithub.com (d) are different registered domains, and in github.com/docs (c) the /docs part is a path, not a subdomain.

Question 13 · Short answer

Give two reasons why the web uses domain names instead of making people type IP addresses.

Any two of:

  • Names are easy for people to remember; numbers are not.
  • The IP address behind a name can change (new server, new host) without users having to learn a new address.
  • One name can lead to many servers (big sites, CDNs), and one server can host many names.

Question 14 · Compare

Which of these addresses have the same origin as http://localhost:3000/dashboard? Explain each answer.

  1. http://localhost:3000/login
  2. https://localhost:3000/dashboard
  3. http://localhost:5173/dashboard
  4. http://127.0.0.1:3000/dashboard

Only a. The origin is scheme + host + port (http, localhost, 3000); the path doesn’t count, so a differs only in its path. b has a different scheme (https), c a different port (5173), and d a different host: 127.0.0.1 is the address behind localhost, but to a browser the name and the number are two different origins.

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?

localhost (127.0.0.1) always means “this computer”, so on your friend’s laptop the address points to their laptop, where your app isn’t running (or another program uses port 3000). To share the app, you put it on a server that others can reach, with a real domain name, for example by deploying it to Vercel.

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.

No. The browser proves the server is answering web (HTTP/HTTPS) requests. Many servers and firewalls are set to ignore ping messages, which are a different kind of traffic. “Request timed out” only means no ping replies came back. To test a web server, use the browser or curl -I instead.

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?

www.amazon.com is an alias (CNAME) for other names, ending at a name that belongs to Akamai, a CDN company. So your browser is not connecting to “Amazon’s one computer” but to a nearby server in a content delivery network that Amazon uses to serve visitors quickly around the world.

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.

  1. The browser takes the domain name www.example.com from the URL.
  2. It asks DNS (its cache, then the resolver) for the IP address behind that name.
  3. It connects to that IP address on port 443, because the scheme is HTTPS, and sets up an encrypted connection (checking the server’s certificate).
  4. It sends an HTTP request: GET /about.
  5. The server sends a response: status 200 plus the HTML of the page.
  6. The browser reads the HTML and sends more requests for the CSS, JavaScript and images it mentions, then draws the page.

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?

It makes www.myclubapp.com an alias for the hosting service’s name. When someone looks up www.myclubapp.com, DNS follows the alias to the hosting service’s servers, so visitors reach your app there. You add the record in the DNS settings at your registrar (or wherever your domain’s DNS is managed), then wait for caches to pick up the change.

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?

Scheme http://, host localhost, port 3000, path /events, query string ?id=7, fragment #details. The scheme, host and port decide where the request goes (the program on port 3000 on this computer). The server receives the path and the query string (/events?id=7). The fragment #details 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).

  • Registering a domain rents the name (for example myclubapp.com) from a registrar, usually for a year at a time. It doesn’t store any website.
  • Hosting means a server somewhere actually stores and serves the website’s files and code.
  • DNS records connect the two: they point the registered name at the hosting service’s servers.

At first you need neither a paid domain nor paid hosting: many hosting services give you a free address on their own domain (such as yourclub.github.io). A custom domain is an optional upgrade that makes the address shorter and more professional - and its registration must be kept up (usually renewed every year).

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.

Partly wrong. The domain name is not case-sensitive, so WWW.Example.com and www.example.com are the same server. The path (/About vs /about) may or may not be case-sensitive - that depends on the server. Many servers (especially on Linux) treat them as different, so the two URLs might lead to different pages, but not because of the domain.

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.

Results vary - that is the point. Typical observations: big sites often return several addresses (and IPv6 ones), some names are aliases that end at a CDN, and smaller sites may return a single address with no aliases. Ping times depend on how far away (in network terms) the answering server is, so a friend on another network may see different addresses and different times for the same name.

© 2025-2026 Y. Rosenthal. All rights reserved.