Logo

dev-resources.site

for different kinds of informations.

How to understand the ins and outs of how DNS really works.

Published at
12/12/2024
Categories
webdev
api
dns
Author
xmanhugo
Categories
3 categories in total
webdev
open
api
open
dns
open
Author
8 person written this
xmanhugo
open
How to understand the ins and outs of how DNS really works.

We're working on a project that needs some teamwork across different teams, and we’ve got to connect to an API. Since the outside team can't just jump in and edit my API definitions, we thought we'd use Apidog's doc publishing feature. I looked through their help docs and found out that the API docs update in real-time and you can even debug right there on the page, and today I realized I can customize the domain name for the published docs, which is an awesome feature for me:

After designing/developing your API in Apidog, you can easily share the API with other colleagues or publish it to the public

While we were working on it, one of my teammates asked, “What’s a CNAME?” I just gave a quick rundown based on what I know. It sparked a great discussion, and it made me want to dig deeper into the whole DNS thing and really get a better grasp on it.

The way DNS works is often taken for granted. Basically, DNS is used for converting website names into IP addresses, so you can think of it like this: you input a URL, and it spits out an IP.

the way how dns works

DNS mainly uses this protocol, which is based on UDP. Because of this, DNS servers can handle an incredible number of queries per second—much higher than web servers, which rely on TCP. It’s important to know about different types of DNS records, including:

  • A records: these link a domain name to an IPv4 address.
  • AAAA records: these link a domain name to an IPv6 address.
  • CNAME records: used for forwarding during the query process.
  1. When you type www.apidog.com into your browser, the DNS protocol actually uses www.apidog.com. It ends with a dot ., but that’s usually not shown for looks.
  2. The browser first checks its local cache (like the host file or browser history) to see if it already has a record for that domain. If it does, it uses that.
  3. If not, the browser sends a DNS request to the ISP’s DNS server, often called local DNS.
  4. The local DNS checks its own cache. It’s important that the caching time is just right—too long or too short can cause issues. Also, how local DNS queries work is up to the ISP, which can get pretty complicated.
  5. If local DNS doesn’t have the information cached, it starts scanning the domain name from right to left, asking the proper servers along the way. For www.apidog.com, it first checks with the root name server (those rare servers that handle .). They will tell it who is in charge of .com, leading the local DNS to look for the server that manages .com (let’s call that S1) to find out who manages apidog.com. Usually, S1 returns a CNAME record, redirecting the query to the authoritative DNS server.
  6. The authoritative server looks up its settings to find the server for www.apidog.com and sends back an IP address.
  7. Local DNS caches that IP address and sends it back to the browser.
  8. Finally, the browser establishes a TCP connection with that IP address's server and sends an HTTP request.

For anyone who’s bought a domain, you know that if you want to start an AI project and buy the domain xmanhugo.com from GoDaddy, and then you want to create a subdomain like ai.xmanhugo.com, you need to set up an A record in GoDaddy’s dashboard to point ai.xmanhugo.com to a specific IP. Each time you set up a subdomain, you follow this same process. Knowing how DNS resolution works lets you do a few things:

  1. Set up a DNS server on D1, making it the authoritative DNS server for xmanhugo.com.
  2. In Wanwang’s dashboard, add a new CNAME record to redirect xmanhugo.com queries to D1.
  3. D1 can return any IP address it chooses.

With this setup, you gain total control since D1 is yours, and you won’t need to access Wanwang’s console anymore. This is what running your own DNS server gets you!

dns Article's
30 articles in total
Favicon
Building and Deploying a New API (Part 3)
Favicon
Configuring a custom domain for your Azure Static Web App
Favicon
วิธีติดตั้งและกำหนดค่าเบื้องต้นสำหรับเซิร์ฟเวอร์ DNS บน Ubuntu 22.04 LTS แบบง่าย ๆ
Favicon
Email Verifier using Go
Favicon
What are DNS records?
Favicon
How to understand the ins and outs of how DNS really works.
Favicon
How to Simplify DNS Management in a Multi-Account Environment with Route 53 Resolver
Favicon
How to Add an Elastic (Static) IP to Your EC2 Instance And Update Your DNS Records on Route53
Favicon
DNS Spoofing: Controlling DNS Requests on the Network
Favicon
DHCP dinamik DNS güncellemesi
Favicon
Migrate a hosted zone to a different AWS account in few seconds!!
Favicon
Explaining DNS NXDOMAIN status in SOA Record Type: On Non-Existing Domains
Favicon
Instant Domain Insights: Why Every Tech Professional Needs DNS Checker Pro
Favicon
Automating DNS Management in Kubernetes with ExternalDNS
Favicon
DNS-load-balancing
Favicon
Verify your Bluesky or Mastodon account on your own domain, with a free website!
Favicon
How to Install and Configure a Private BIND DNS Server on Ubuntu 22.04
Favicon
How to Add DNS Records for Your Domain in Route53
Favicon
AWS S3 Change Url, Proxy Url, Map to Domain in 2024
Favicon
From WHOIS to SSL: How DNS Checker Pro Unveils the Hidden Details of Any Website
Favicon
Automating AWS DNS Firewall Domain List Updates Using S3, Lambda, and CLI
Favicon
Explaining CAA DNS Record
Favicon
Mastering DNS Spoofing with Bettercap: A Comprehensive Guide
Favicon
Issue 65 of AWS Cloud Security Weekly
Favicon
Unlocking the Internet's Address Book: DNS Roots Explained!
Favicon
I bought us-east-1.com: A Look at Security, DNS Traffic, and Protecting AWS Users
Favicon
Unlocking the Power of AWS Route 53: Your Complete Guide to DNS Management
Favicon
DNS: More Than Just a Web Directory
Favicon
Automating DNS with Confidence: Terraform + DNScontrol
Favicon
"Message Not Delivered" - What to Do When Your Email Bounces Back?

Featured ones: