Domain & Hosting Connection: DNS, Hosting & Email
Read on to explore domain & hosting connection: dns, hosting & email — a beginner-friendly walkthrough by Codekilla.
When you type a website address into your browser, a complex but elegant dance happens behind the scenes. Your domain name (like mysite.com) is just a human-friendly label—it needs to point to an actual computer (server) where your website files live. This connection between your domain and hosting is orchestrated by the Domain Name System (DNS), which acts like the internet's phone book. DNS translates your domain into an IP address, telling browsers exactly where to find your site's content.
Think of it this way: your domain is your street address, your hosting is the actual building where you store your stuff, and DNS is the postal service that makes sure letters (web requests) reach the right building. Email adds another layer—it uses the same domain name but routes to different servers through specific DNS records. Understanding how these pieces fit together is essential for launching any web project.
- Website accessibility: Without proper DNS configuration, visitors can't reach your site even if it's perfectly built and hosted
- Email delivery: Misconfigured DNS records mean your business emails bounce or land in spam folders
- Performance control: DNS settings determine how quickly your site resolves and loads for users worldwide
- Security foundation: Proper DNS and hosting setup protects against hijacking, spoofing, and downtime
- Professional credibility: Custom email addresses (
hello@yourbrand.com) instead of Gmail addresses signal legitimacy to customers
DNS servers store records that map domain names to resources. When someone visits your site, their browser queries DNS servers asking "Where is example.com?" The DNS server responds with an IP address like 192.0.2.1, and the browser connects to that server to fetch your website.
There are several DNS record types, but four matter most for beginners:
| Record Type | Purpose | Example |
|---|---|---|
| A Record | Points domain to IPv4 address | example.com → 192.0.2.1 |
| CNAME | Creates an alias to another domain | www.example.com → example.com |
| MX Record | Directs email to mail servers | example.com → mail.provider.com |
| TXT Record | Stores text data for verification/security | SPF, DKIM authentication strings |
DNS changes don't happen instantly. There's a propagation period (usually 1-48 hours) where different servers worldwide update their cached information. This is why you might see your old site on one device and the new one on another right after making changes.
bash# Check current DNS records for a domain dig example.com A dig example.com MX dig example.com TXT # Output shows which servers your domain currently points to # A record output example: # example.com. 300 IN A 192.0.2.1
Web hosting is physical server space where your website files, databases, and media live. When you purchase hosting, the provider gives you nameservers (like ns1.hostingprovider.com) and an IP address. You then configure your domain's DNS to point to these nameservers.
The connection happens in two common ways:
Method 1: Nameserver delegation — You tell your domain registrar to use your hosting provider's nameservers. This gives the hosting company full control over all DNS records. Most beginners should use this method because hosting companies auto-configure everything.
Method 2: A record pointing — You keep your domain's default nameservers but manually add an A record pointing to your hosting IP address. This gives you more control but requires manual configuration of MX records for email.
javascript// This is NOT code you run—it's a conceptual view // of how browsers resolve your domain const resolveDomain = async (domain) => { // 1. Browser checks local cache let ip = checkCache(domain); // 2. If not cached, query DNS servers if (!ip) { const dnsResponse = await queryDNS(domain); ip = dnsResponse.records.A[0]; // Gets IP from A record } // 3. Connect to that IP address const websiteContent = await fetch(`http://${ip}`); return websiteContent; };
Your domain can handle email separately from your website hosting. Most hosting plans include basic email, but many developers use specialized email providers (Google Workspace, Microsoft 365, ProtonMail) for better deliverability and features.
Email routing is controlled entirely by MX (Mail Exchange) records. These tell sending servers where to deliver messages for your domain. You can host your website with one company and email with another—they're independent.
SPF, DKIM, and DMARC records (all TXT records) prove your emails are legitimate:
- SPF lists which servers can send email for your domain
- DKIM adds a digital signature to your messages
- DMARC tells receiving servers what to do with emails that fail SPF/DKIM checks
Without these, your emails often land in spam or get rejected entirely.
dns; Example DNS zone file snippet showing email records ; (This is configuration format, not executable code) example.com. IN MX 10 mail.google.com. example.com. IN TXT "v=spf1 include:_spf.google.com ~all" default._domainkey IN TXT "v=DKIM1; k=rsa; p=MIGfMA0GCS..." _dmarc.example.com. IN TXT "v=DMARC1; p=quarantine; rua=mailto:admin@example.com"
DNS propagation is the time it takes for changes to spread across the internet's DNS servers. Each DNS record has a TTL (Time To Live) value—usually 300 seconds to 86400 seconds—that determines how long servers cache the information before checking for updates.
When you change DNS records, some users see the new configuration immediately while others see the old one until their local DNS cache expires. This is normal, not broken.
| Problem | Likely Cause | Solution |
|---|---|---|
| Site not loading after setup | DNS not propagated yet | Wait 24-48 hours, check with dig or online DNS tools |
Works without www but not with it | Missing CNAME record for www | Add CNAME: www → @ or your root domain |
| Emails bouncing | Incorrect MX records | Verify MX records match your email provider's documentation |
| Old site still showing | Browser/DNS cache | Clear browser cache and flush local DNS (ipconfig /flushdns on Windows) |
bash# Flush DNS cache on different systems # Windows ipconfig /flushdns # macOS sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder # Linux sudo systemd-resolve --flush-caches # Check if propagation is complete globally nslookup example.com 8.8.8.8 # Query Google's DNS nslookup example.com 1.1.1.1 # Query Cloudflare's DNS
| Need | Reach For |
|---|---|
| Point domain to hosting | Change nameservers at domain registrar OR add A record with hosting IP |
Add www version of site | Create CNAME record: www → @ |
| Set up custom email | Add MX records from email provider (Google, Microsoft, etc.) |
| Verify domain ownership | Add TXT record provided by service (Google Search Console, etc.) |
| Improve email deliverability | Configure SPF, DKIM, and DMARC TXT records |
| Check DNS changes | Use dig, nslookup, or online DNS checker tools |
| Speed up future changes | Lower TTL values before making updates (change back after) |
-
Changing nameservers AND adding manual DNS records — Pick one method. If you delegate nameservers to your host, manual DNS records at your registrar won't work because the host's nameservers override them completely.
-
Deleting default DNS records — When you switch to custom nameservers, don't delete the parking page A records until your new hosting is ready. You'll break your site during the transition window.
-
Forgetting MX records when switching nameservers — If you're using third-party email (Gmail, Outlook), you MUST re-add those MX records after changing nameservers or email stops working.
-
Not waiting for propagation — Making a DNS change, seeing it not work after 10 minutes, then changing it back creates confusion. Changes need 1-48 hours to fully propagate worldwide.
-
Using low TTL values permanently — While 300-second TTL lets you make quick changes, it forces DNS lookups more often, slightly slowing your site. Use 3600-86400 seconds normally.
-
Pointing root domain and www to different places accidentally — Your root domain (
example.com) and subdomain (www.example.com) should generally point to the same website unless you intentionally want different content.
💡 Think Like a Programmer: DNS is declarative, not imperative—you declare what SHOULD be true (this domain points to this IP), then multiple systems work independently to make it true. When debugging, check what different DNS servers currently believe is true, not just what you configured.
Keep Reading
Web Development Basics: HTML, CSS & JavaScript Notes
Read on to explore web development basics: html, css & javascript notes — a beginner-friendly walkthrough by Codekilla.
Web Hosting Fundamentals: Types, Resources & Plans
Read on to explore web hosting fundamentals: types, resources & plans — a beginner-friendly walkthrough by Codekilla.
Domain Purchase & Registration Guide
Read on to explore domain purchase & registration guide — a beginner-friendly walkthrough by Codekilla.
