Please enable JavaScript to use CodeHS

Web Hosting

Domains and DNS

A domain name is the address people type to find your site. DNS is the system that turns that friendly name into the IP address where your files actually live. If you want your own yourname.com, you need to understand both.

DNS ~10 min Middle / High School
The Big Idea

Domain names

A domain name is a human-readable address for a website. codehs.com, google.com, and wikipedia.org are all domain names. They are easier to remember than IP addresses, which are long strings of numbers.

Domain names have parts. The top-level domain (TLD) is the ending, like .com, .org, .edu, or .net. The second-level domain is the main name, like codehs. You can also have subdomains, like blog.example.com or shop.example.com.


How It Works

Registrars and ownership

Domain names are registered through companies called registrars, such as Namecheap, Google Domains, Cloudflare, or GoDaddy. You pay a yearly fee to keep the name. The registrar records your ownership in a global database.

When you register a domain, you also configure its nameservers. Nameservers are the DNS servers that hold the actual records for your domain. Many hosting providers give you nameservers to use, or you can manage DNS through your registrar.


Vocabulary

DNS records

DNS records are entries that tell the internet what to do with your domain. The most common types are:

  • A record: points a domain to an IPv4 address, like 203.0.113.42.
  • AAAA record: points a domain to an IPv6 address, the newer, longer version of an IP address.
  • CNAME record: points a subdomain to another domain name, like pointing www to example.com.
  • MX record: tells email services where to send mail for your domain.
  • TXT record: stores text information, often used for verification and security settings.

Real World

Propagation and TTL

When you change a DNS record, it does not update everywhere instantly. DNS servers around the world cache records to save time. Each record has a TTL (time to live) that says how long it can be cached.

If your TTL is one hour, most users will see your new record within an hour. If your TTL is a day, it can take a day. That is why changing DNS can feel slow even though the actual edit takes only a few seconds.

Tip: before making a big DNS change, lower your TTL to a few minutes. After the change is stable, you can raise it again to improve performance.


Interactive

DNS record builder

Fill in a simple DNS table below, then click Test lookup to see what a browser would do. Try an A record for the root domain and a CNAME for www.

TypeNameValue
A
CNAME
Result will appear here.

Code

Resolving a domain name

DNS is like a phone book for the internet. This Python script asks the operating system to turn a domain name into an IP address.


Your Turn

Check yourself

Why do you need DNS if your website already has an IP address?

Your answer:

Sample answer: IP addresses are hard for humans to remember. DNS maps easy-to-remember domain names to IP addresses so browsers can find the right server. It also lets you change servers without changing the domain people type.


Check Yourself

Quick quiz

1. What does an A record do?

2. What is a registrar?

3. Why might a DNS change take time to reach everyone?

Keep learning

You understand domains and DNS. Next, deploy your files and make the site live.

Part of the Web Hosting series.