When you create or modify DNS records (like A, CNAME, or MX records), the changes don't take effect instantly worldwide. DNS propagation refers to the time it takes for these changes to disseminate across all DNS servers globally. This process typically takes anywhere from a few minutes to 48 hours, depending on TTL (Time To Live) settings and ISP caching.
Instead of just relying on ping (which only checks basic connectivity), developers should use these more robust methods:
# Using dig (Linux/macOS)
dig +short my.subdomain.com A
# Using nslookup (Windows)
nslookup -type=A my.subdomain.com
These services check DNS records from multiple global locations:
For automated testing in your CI/CD pipeline or scripts:
# Python example using dnspython
import dns.resolver
def check_dns_propagation(domain, record_type='A', expected_value=None):
try:
answers = dns.resolver.resolve(domain, record_type)
records = [r.to_text() for r in answers]
if expected_value:
return expected_value in records
return records
except Exception as e:
return False
# Usage
print(check_dns_propagation('my.subdomain.com', 'A', '192.0.2.1'))
The TTL value (in seconds) specified in your DNS records determines how long resolvers should cache the information. Lower TTL values (e.g., 300 seconds) mean faster propagation when changing records, while higher values (86400 seconds) reduce DNS load but slow propagation.
- Flush your local DNS cache:
ipconfig /flushdns
(Windows) orsudo dscacheutil -flushcache
(macOS) - Check with different DNS providers:
dig @8.8.8.8 my.subdomain.com
(Google DNS) - Verify DNSSEC validation if applicable
When you create or modify DNS records like A records for subdomains, propagation delays can occur due to TTL (Time To Live) settings and caching across DNS servers worldwide. Unlike what many developers assume, a simple ping test isn't always reliable for verification.
Here are professional techniques to verify your DNS changes:
# 1. Using dig (Linux/macOS)
dig +short my.subdomain.com A
# 2. Using nslookup (Windows)
nslookup -querytype=A my.subdomain.com
# 3. Using Python for programmatic checks
import socket
try:
print(socket.gethostbyname('my.subdomain.com'))
except socket.gaierror:
print("DNS not yet propagated")
For comprehensive verification across different locations:
- Google's Public DNS (8.8.8.8):
dig @8.8.8.8 my.subdomain.com
- Cloudflare's DNS (1.1.1.1):
nslookup my.subdomain.com 1.1.1.1
- Online tools like DNSchecker.org or WhatsMyDNS.net
For production environments, consider these robust approaches:
#!/bin/bash
# Check multiple DNS servers simultaneously
SERVERS=("8.8.8.8" "1.1.1.1" "9.9.9.9")
DOMAIN="my.subdomain.com"
for server in "${SERVERS[@]}"; do
echo "Checking $server:"
dig +short @$server $DOMAIN A || \
nslookup -querytype=A $DOMAIN $server | grep Address
done
Watch out for these issues:
- TTL conflicts: Old TTL values may cause delays
- Browser cache: Always test in incognito mode
- Local DNS cache: Flush with
ipconfig /flushdns
(Windows) orsudo dscacheutil -flushcache
(macOS)
For critical deployments, implement this Python monitor:
import dns.resolver
import time
def check_dns(domain, expected_ip, timeout=60):
resolver = dns.resolver.Resolver()
resolver.nameservers = ['8.8.8.8']
start_time = time.time()
while time.time() - start_time < timeout:
try:
answers = resolver.resolve(domain, 'A')
for rdata in answers:
if rdata.address == expected_ip:
return True
except:
pass
time.sleep(5)
return False