CDN (Content Delivery Network) accelerates content delivery by deploying edge nodes globally and caching website content on servers closest to users. DNS plays the intelligent scheduling core role in CDN, determining which edge node users access.
How CDN Works
Traditional Access vs CDN Access
Traditional Access:
shellUser (Beijing) → Origin Server (USA) → Returns content ↓ High latency, slow speed
CDN Acceleration:
shellUser (Beijing) → DNS Intelligent Scheduling → CDN Beijing Node → Returns cached content ↓ Low latency, fast speed
Role of DNS in CDN
1. CNAME Integration
Users point their domain to the CNAME address provided by CDN:
dns; User domain configuration www.example.com. 600 IN CNAME www.example.com.cdn-provider.com.
2. Intelligent DNS Resolution
CDN's DNS server decides which edge node IP to return based on multiple factors:
shellUser queries www.example.com ↓ CNAME to CDN domain ↓ CDN DNS Server ↓ Intelligent Scheduling Algorithm ↓ Returns optimal node IP
CDN DNS Scheduling Strategies
1. Geographic Scheduling
Principle: Return the nearest CDN node based on user's geographic location
shellBeijing user → Returns Beijing CDN node IP Shanghai user → Returns Shanghai CDN node IP Guangzhou user → Returns Guangzhou CDN node IP US user → Returns US CDN node IP
Implementation:
- Determine location based on user DNS query source IP
- Use GeoIP database
- Return geographically closest node
2. ISP Scheduling
Principle: Return nodes from the same ISP based on user's ISP
shellChina Telecom user → Returns China Telecom line CDN node China Unicom user → Returns China Unicom line CDN node China Mobile user → Returns China Mobile line CDN node
Advantages:
- Avoid cross-ISP access
- Reduce network latency
- Improve transmission speed
3. Load Balancing Scheduling
Principle: Allocate users to lower-load nodes based on node load conditions
shellNode A: 80% load → Reduce allocation Node B: 50% load → Normal allocation Node C: 30% load → Priority allocation
Monitoring Metrics:
- CPU usage
- Bandwidth usage
- Concurrent connections
- Response time
4. Health Check Scheduling
Principle: Automatically detect node health status and remove faulty nodes
shellNode A: Healthy ✅ → Normal service Node B: Faulty ❌ → Automatically removed Node C: Healthy ✅ → Normal service
Health Check Methods:
- HTTP status code check
- TCP port check
- Response time check
CDN DNS Resolution Process Details
Complete Resolution Process
shell1. User enters www.example.com ↓ 2. Local DNS query ↓ 3. Returns CNAME: www.example.com.cdn-provider.com ↓ 4. Queries CDN DNS server ↓ 5. CDN DNS analyzes user source IP ↓ 6. Applies scheduling strategy (geographic + ISP + load) ↓ 7. Returns optimal CDN node IP (e.g., 203.0.113.10) 8. User accesses CDN node to get content
First Visit vs Cached Visit
First Visit (Not Cached):
shellUser → CDN Node → Origin pull from source → Cache content → Return to user
Cached Visit:
shellUser → CDN Node (directly returns cached content)
CDN DNS Configuration Examples
Scenario 1: Full Site Acceleration
dns; Main domain CNAME to CDN www.example.com. 600 IN CNAME example.cdn-provider.com. ; Static resources domain CNAME to CDN static.example.com. 600 IN CNAME static.example.cdn-provider.com. ; Images domain CNAME to CDN img.example.com. 600 IN CNAME img.example.cdn-provider.com.
Scenario 2: Dynamic/Static Separation
dns; Dynamic content (not through CDN) www.example.com. 600 IN A 192.0.2.1 ; Static content (using CDN) static.example.com. 600 IN CNAME static.example.cdn-provider.com. css.example.com. 600 IN CNAME static.example.cdn-provider.com. js.example.com. 600 IN CNAME static.example.cdn-provider.com.
Scenario 3: Multi-CDN Vendors
dns; Primary CDN www.example.com. 600 IN CNAME example.cdn1-provider.com. ; Backup CDN (through weight or geographic distribution) ; Some DNS services support intelligent distribution
CDN DNS TTL Settings
Impact of TTL on CDN
| TTL Setting | Advantages | Disadvantages |
|---|---|---|
| Short TTL (60-300s) | Fast failover, flexible scheduling | Increased DNS queries, origin pressure |
| Long TTL (3600s+) | Reduced DNS queries, better caching | Slow failover, inflexible scheduling |
Recommended Configuration
dns; Main domain - Medium TTL www.example.com. 600 IN CNAME example.cdn-provider.com. ; Static resources - Longer TTL static.example.com. 3600 IN CNAME static.example.cdn-provider.com.
Common CDN DNS Issues
Issue 1: DNS Cache Causes Scheduling Failure
Symptoms:
- Users scheduled to faulty nodes
- Some users still access old nodes after node change
Solution:
- Lower TTL value
- Wait for cache expiration
- Use CDN's force refresh feature
Issue 2: Cross-ISP Access Slow
Symptoms:
- China Telecom users accessing China Unicom CDN nodes
- High latency, slow speed
Solution:
- Ensure CDN supports ISP scheduling
- Check if DNS configuration is correct
- Contact CDN provider for optimization
Issue 3: Origin IP Exposure
Symptoms:
- Direct ping to origin domain gets real IP
- Attackers bypass CDN to directly attack origin
Solution:
- Origin only allows CDN IP range access
- Use firewall to restrict direct access
- Separate origin domain and access domain
DNS Configuration for Major CDN Providers
Cloudflare
dns; Change NS records to Cloudflare example.com. 86400 IN NS lara.ns.cloudflare.com. example.com. 86400 IN NS greg.ns.cloudflare.com.
Characteristics:
- Takes over entire domain DNS
- Automatic CDN acceleration
- Supports CNAME Flattening
Alibaba Cloud CDN
dns; CNAME integration www.example.com. 600 IN CNAME www.example.com.w.kunlunar.com.
Characteristics:
- Supports intelligent scheduling (geographic + ISP)
- Rich domestic nodes
AWS CloudFront
dns; CNAME integration www.example.com. 600 IN CNAME d1234abcd5678.cloudfront.net.
Characteristics:
- Global node distribution
- Integrated with AWS ecosystem
CDN DNS Optimization Tips
1. Use HTTP DNS
Bypass local DNS, directly get optimal node through HTTP:
shellClient → HTTP DNS Service → Returns optimal CDN IP
Advantages:
- Avoid DNS hijacking
- More precise scheduling
- Real-time updates
2. Preheating and Refreshing
Preheating: Push popular content to CDN nodes before peak hours Refreshing: Actively clear CDN cache, force origin pull
3. Monitoring and Analysis
- Monitor node response times
- Analyze user geographic distribution
- Optimize scheduling strategies
Common Interview Questions
Q: How does CDN know user location?
A:
- Through the source IP address of user DNS queries
- Use GeoIP database to query IP's corresponding geographic location
- Return the nearest CDN node
Q: Why is CDN CNAME record TTL usually set shorter?
A:
- Facilitates fast failover
- Supports dynamic scheduling strategies
- Adapts to node scaling
- But increases DNS query volume
Q: If CDN node fails, how does DNS switch?
A:
- CDN's health check system detects node failure
- Automatically removes the node from DNS resolution results
- Users get healthy node IP on next query
- Automatically adds back after recovery
Summary
| Aspect | Description |
|---|---|
| Core Function | Intelligently schedule users to optimal CDN nodes |
| Scheduling Strategies | Geographic location, ISP, load, health status |
| Integration Method | CNAME points to CDN-provided domain |
| TTL Settings | Balance scheduling flexibility and DNS query volume |
| Optimization Directions | HTTP DNS, preheating/refreshing, monitoring/analysis |
DNS is the "brain" of CDN. Through intelligent scheduling algorithms, it ensures users always access the optimal edge node, thereby achieving acceleration effects.