
A hosting outage rarely starts with a dramatic “everything is down.” Usually one piece stops cooperating. A VPS stops answering on 443. A database node drops off the network. A reverse proxy process crashes. If DNS keeps sending users to the dead IP, they stall, retry, and bounce.
This DNS failover setup guide tutorial walks through a practical 2026 approach. You’ll use low TTLs on the record you’ll flip. You’ll keep a standby target ready, verify health fast, and cut over without guessing.
This is for VPS and dedicated server operators who want a controlled, repeatable failover path. You’ll use a simple “primary + standby” pattern. It works for WordPress, typical PHP sites, and small SaaS apps behind Nginx or Apache.
No exotic tooling. Just careful DNS choices and checks you can run under pressure.
What you’re building (and what it won’t do)
You’re setting up DNS-based failover for a hostname like www.example.com (and optionally example.com). The behavior is simple:
- Normal state: DNS points to Primary (VPS A).
- Failover state: you switch DNS to Standby (VPS B) quickly because you planned TTL and verified the standby is ready.
What DNS failover won’t do: instant rerouting. Caches sit everywhere. That includes recursive resolvers, ISP caches, and sometimes local clients.
A low TTL reduces the wait. You’ll still have a “tail” of users reaching the old IP for a while.
If you need near-instant shifting, that’s a load balancer/anycast problem and outside the scope here.
Prerequisites checklist (10 minutes upfront saves hours later)
- A domain you control. If you need one, register it via HostMyCode domains.
- Two targets: Primary IP (VPS/dedicated) and Standby IP (VPS/dedicated). For predictable performance, run both on the same class of server.
- Access to DNS records (your authoritative DNS provider’s panel/API).
- SSL plan: either the same certificate works on both servers, or you can issue on the standby too.
If your server builds aren’t standardized yet, fix that first. Consistent firewall rules, package versions, and service layouts make failover boring—in the best way.
Two HostMyCode tutorials that pair well with this:
Step 1: Decide your failover model (A/AAAA vs CNAME vs ALIAS)
Pick a DNS record strategy that fits your DNS provider and how you run the domain:
- A/AAAA records (most common):
wwwpoints directly to IP(s). Easy to reason about and quick to change. - CNAME to an “active” name:
wwwpoints toactive.example.com, and you switchactivefrom Primary to Standby. This gives you one clean “flip” point. - ALIAS/ANAME (provider-specific): CNAME-like behavior at the apex. Useful if you need the root domain to follow an “active” hostname.
Recommended for most hosting setups:
www.example.comas a CNAME toactive.example.comactive.example.comas an A record to Primary (and later Standby)
This pattern keeps incident work small. You change one record (active) and leave everything else untouched.
Step 2: Set TTLs that actually allow fast cutover
TTL sets your recovery pace. If the TTL is high, you can flip DNS and still wait hours for real-world results.
A practical 2026 baseline for many sites looks like this:
- Normal operations: 300 seconds (5 minutes)
- High-risk windows (migration, major release, planned maintenance): 60–120 seconds for 24–48 hours
Avoid TTLs like 10 seconds unless you’ve proven your DNS provider can handle the query rate. Also confirm you’re comfortable with the extra churn.
For most small and mid-sized sites, 60–120 seconds during planned work is plenty.
Keep the low TTL focused on the record you’ll actually flip (for example, active.example.com). Don’t drag every record down unless you have a reason.
Step 3: Prepare the standby server so it can take traffic immediately
DNS failover only works if the standby isn’t a “we’ll configure it later” box. At minimum, it must serve the correct vhost, respond on HTTPS, and return the content you expect.
3.1 Provision the standby (VPS or dedicated)
For a warm standby, a VPS with consistent CPU and NVMe is usually fine. For high-revenue workloads, dedicated resources reduce the odds that a neighbor’s load becomes your problem.
- For full control: a HostMyCode VPS is a clean choice for primary and standby pairs.
- If you want patching, updates, and “someone watches it” operations: use managed VPS hosting.
3.2 Match the web stack and vhost config
Keep the stack consistent. If Primary runs Nginx + PHP-FPM, Standby should run the same versions and the same layout.
The goal is to remove “works on one box” surprises.
For Nginx, you’ll typically mirror:
/etc/nginx/nginx.conf/etc/nginx/sites-available/and/etc/nginx/sites-enabled//etc/php/8.3/fpm/pool.d/(PHP 8.3 is common in 2026 hosting builds)
Quick diagnostic on Standby:
sudo nginx -t
sudo systemctl status nginx --no-pager
curl -I http://127.0.0.1
3.3 Make SSL failover-safe
Two approaches work reliably:
- Option A (recommended): install the same certificate + key on both servers (common with paid certs, and also workable with many ACME setups if you copy issued certs securely).
- Option B: issue Let’s Encrypt certificates separately on each server. This is straightforward, but watch the failure mode.
If Standby is “cold” and DNS doesn’t point to it, HTTP-01 challenges can fail. Use DNS-01 challenges if you want issuance that doesn’t depend on traffic routing.
For a standard Nginx + Let’s Encrypt workflow, follow: SSL certificate setup on Ubuntu VPS (2026).
3.4 If you host WordPress: sync uploads and wp-config settings
WordPress failover tends to break in predictable ways. The usual causes are missing uploads, config drift, or a database plan that only exists in someone’s head.
At minimum:
- Keep
wp-content/uploadssynced (rsync, object storage, or shared storage). - Keep
wp-config.phpidentical between hosts (salts, table prefix, and site URLs). - Plan how the database will be available (same DB endpoint, or restored copy, or replicated—keep it simple if you can).
Even without database replication, DNS failover can still save you from pure web-tier outages. That assumes the database remains reachable.
Step 4: Create “active” DNS records (the switch you flip)
In your DNS zone, create records like these:
active.example.com→ A → PRIMARY_IP (TTL 60–300)www.example.com→ CNAME →active.example.com(TTL 300)
If you also want the apex (example.com) to fail over, two common patterns work well:
- Redirect apex to www (simple and clean): keep apex on a small redirect vhost, or use your DNS provider’s redirect feature.
- Apex follows active using ALIAS/ANAME (provider feature): set
example.comto aliasactive.example.com.
After creating records, confirm what your authoritative DNS is actually serving:
# Replace ns1.yourdns.tld with one of your authoritative nameservers
DIG_NS="ns1.yourdns.tld"
dig @${DIG_NS} active.example.com A +noall +answer
dig @${DIG_NS} www.example.com CNAME +noall +answer
Step 5: Validate standby without changing public DNS
You want evidence that Standby works before you’re on a live incident call. The simplest approach is to test Standby by IP while forcing the hostname.
Test HTTPS with SNI + Host header
STANDBY_IP="203.0.113.20"
HOSTNAME="www.example.com"
# Show which certificate you get and ensure the vhost routes correctly
curl -vk --resolve ${HOSTNAME}:443:${STANDBY_IP} https://${HOSTNAME}/
Check for:
- The HTTP status codes you expect (200/301/302, not a default-vhost 404).
- A certificate that matches the hostname (or at least behaves the way your clients require).
- Real content: homepage loads and critical assets return 200.
Quick port checks from your laptop
nc -vz 203.0.113.10 443 # Primary
nc -vz 203.0.113.20 443 # Standby
If Standby isn’t reachable on 443, DNS failover won’t save you. Fix firewall rules, security groups, or service health now—while it’s quiet.
Step 6: Add a lightweight health check routine (so failover isn’t a blind decision)
Many outages are “half outages.” TLS handshakes still succeed, but the app is dead. Or the homepage loads, but checkout fails.
Keep your health checks small and fast. Tie them to what matters for your site.
Create an explicit health endpoint
On each server, create a file that bypasses heavy app logic. For Nginx:
sudo mkdir -p /var/www/health
echo "ok" | sudo tee /var/www/health/index.html
Then add a location block to your site config (example: /etc/nginx/sites-available/example.com):
location = /healthz {
access_log off;
add_header Content-Type text/plain;
root /var/www/health;
}
Reload safely:
sudo nginx -t && sudo systemctl reload nginx
Now you can check both hosts quickly:
curl -fsS https://www.example.com/healthz
curl -fsS --resolve www.example.com:443:203.0.113.20 https://www.example.com/healthz
If you want a daily “is anything drifting?” signal, add basic reporting. Logwatch still works well for small fleets and keeps noise low: Logwatch setup tutorial (2026).
Step 7: Execute a planned failover (practice run)
Practice once, then practice again after major changes. Run the test during a low-traffic window, and keep it short.
7.1 Lower TTL ahead of time
24 hours before your test, set active.example.com TTL to 60–120 seconds. That gives resolvers time to learn the lower TTL before you need it.
7.2 Flip active to Standby
Edit:
active.example.comA record → change from PRIMARY_IP to STANDBY_IP
Immediately confirm the authoritative answer:
DIG_NS="ns1.yourdns.tld"
dig @${DIG_NS} active.example.com A +noall +answer
7.3 Watch propagation from multiple resolvers
Public resolvers don’t behave identically. Check a few:
dig @1.1.1.1 active.example.com A +short
dig @8.8.8.8 active.example.com A +short
dig @9.9.9.9 active.example.com A +short
Then confirm you can load the site normally:
curl -I https://www.example.com/
7.4 Verify which server is serving traffic
Make the origin obvious by adding a temporary header (different per host). On Primary:
add_header X-Origin primary always;
On Standby:
add_header X-Origin standby always;
Reload and inspect:
curl -I https://www.example.com/ | grep -i x-origin
Remove the header after the test. It’s useful for validation, but it’s also free information about your topology.
7.5 Roll back (fail back to Primary)
Change active.example.com back to PRIMARY_IP. Keep TTL low for an hour while things settle.
Then return it to 300 seconds once stable.
Step 8: Incident-mode failover runbook (copy/paste friendly)
Incidents make smart people sloppy. A runbook keeps you moving in the right order.
- Confirm impact:
curl -I https://www.example.com/from two networks (office + mobile hotspot). - Check Primary quickly:
systemctl status nginx apache2 php8.3-fpm --no-pagerss -lntp | egrep ':80|:443'tail -n 50 /var/log/nginx/error.log
- Check Standby readiness:
curl -vk --resolve www.example.com:443:STANDBY_IP https://www.example.com/healthz
- Flip DNS: change
active.example.comA record to STANDBY_IP. - Verify authoritative answer:
dig @AUTH_NS active.example.com A +short - Verify user path: check from 1–3 public resolvers and load the site normally.
- Communicate: tell stakeholders “DNS cutover initiated; propagation in progress; TTL is X seconds.”
If the root cause is a rebuild (disk failure, corrupted OS, compromised host), pair failover with a recovery plan.
This HostMyCode guide is a good companion: VPS disaster recovery tutorial (2026).
Common pitfalls (and how to avoid them)
- TTL wasn’t lowered ahead of time: if your record had TTL 86400, you can be stuck waiting hours. Keep “switch records” at 300 by default.
- Standby doesn’t have the same firewall openings: confirm 80/443 (and any app ports) are open before you need them. If you keep rules strict, document them and apply the same baseline on both servers.
- SSL breaks on standby: certificate mismatch errors stop real users. Test with
curl --resolveon a schedule. - Mixed content or absolute URLs: some apps embed an origin IP or a hostname that doesn’t fail over. Set a canonical hostname and stick to it in app config.
- Email gets weird after failover: web failover doesn’t fix mail deliverability. If the incident also hits mail, troubleshoot it separately. This guide helps: Postfix mail queue troubleshooting (2026).
Optional: make failover faster during migrations and maintenance
DNS failover isn’t just for emergencies. It’s also a clean way to run planned moves.
Build the new server, validate with --resolve, lower TTL, flip active, then monitor.
If you’re moving to a new VPS and want a near-zero downtime approach, follow a dedicated migration workflow and layer DNS on top: server migration tutorial (2026).
Summary: a practical DNS failover routine you can trust
DNS failover isn’t magic. It works because you keep it simple: one switch record, sensible TTLs, and a standby that’s genuinely ready.
It also needs a short runbook you can follow at 2 a.m.
Test it once, document what broke, and treat it like maintenance—not an emergency-only trick.
If you’re setting up a primary/standby pair for production websites, start with a HostMyCode VPS for each role. Or choose managed VPS hosting if you want help keeping both servers patched and consistent.
If you’re building DNS failover for a business site, start with infrastructure that behaves predictably: stable CPU, clean networking, and consistent performance. HostMyCode’s VPS plans work well for primary/standby pairs, and managed VPS hosting is a good fit if you’d rather offload routine patching and baseline upkeep.
FAQ
How low should TTL be for DNS failover in 2026?
Use 300 seconds for normal operation. Drop to 60–120 seconds 24 hours before maintenance or a planned failover test. Going lower rarely helps much and can increase DNS query volume.
Can DNS failover handle HTTPS without errors?
Yes, if the standby serves the same hostname with a valid certificate. Test with curl --resolve so you catch SNI/vhost issues before an incident.
What about the root domain (example.com) failover?
Easiest: redirect example.com to www.example.com and fail over only www. If you need apex failover, use an ALIAS/ANAME feature if your DNS provider supports it.
Does DNS failover solve database outages too?
No. DNS can reroute web traffic, but your app still needs a reachable database. Many teams use DNS failover for the web tier and rely on backups/restore or replication for data.
How often should I test failover?
At least quarterly, and after major stack changes (web server config, SSL renewal method, firewall changes). Keep the test short and document what you learned.