Skip to content

Split-horizon DNS on cPanel — internal vs external, and why it usually breaks

Serving different DNS answers to internal vs external clients sounds clean. In practice it breaks when users move between networks. Here is how to do it on cPanel and when not to.

A customer wants app.example.com to resolve to 192.168.1.10 (their LAN’s app server) from inside the office and to 203.0.113.10 (the public-facing reverse proxy) from outside. Split-horizon DNS, also called split-view DNS, is the standard answer. cPanel can serve split-horizon with BIND’s view feature. But the operational cost is consistently underestimated — every time a user takes their laptop home, their browser cache and resolver cache fight each other, and the resulting “site isn’t working” tickets eat more time than the architecture saved.

What’s happening

BIND supports views — separate zone files served depending on the client’s source IP. A view is defined in named.conf:

view "internal" {
    match-clients { 192.168.0.0/16; 10.0.0.0/8; };
    zone "example.com" {
        type master;
        file "/var/named/example.com.internal.db";
    };
};

view "external" {
    match-clients { any; };
    zone "example.com" {
        type master;
        file "/var/named/example.com.external.db";
    };
};

When a query comes from 192.168.x.y, BIND serves the internal zone. From anywhere else, the external zone. The two zone files have different A records for the same names.

The cost:

  • Users on VPNs may see internal or external depending on whether the VPN routes DNS too. Users who tether off mobile get external; users on Wi-Fi get internal. Browser caches persist across networks — a user who loaded app.example.com at home and then comes to the office may still hit the external IP.
  • DoH-enabled browsers bypass the local resolver and always get the external view, even from inside the office.
  • The two zones drift over time. Someone updates the external zone but forgets the internal one. Names that should resolve internally start returning external IPs.
  • Troubleshooting is harder. “Is this user’s resolver seeing the internal view or the external view?” is now a question. Without split-horizon, it isn’t.

How to verify

Test from both sides:

# from a host on the internal network
dig +short app.example.com

# from a host on the external network (use a public resolver to simulate)
dig +short app.example.com @1.1.1.1

The answers should differ. If they don’t, the split-horizon isn’t working as intended (or you’re testing from the wrong network).

Check BIND’s view config:

named-checkconf -p | grep -E 'view|match-clients'

Spot-check the two zone files for drift:

diff <(sort /var/named/example.com.internal.db) <(sort /var/named/example.com.external.db)

A long diff is expected if internal/external IPs differ; pay attention to records that should be identical (MX, TXT, NS) and aren’t.

What to do

Before setting up split-horizon, consider the alternative — NAT loopback (also called hairpin NAT). If your firewall supports it, internal clients can resolve app.example.com to the public IP and the firewall translates the connection back to the internal server. One DNS zone, no drift, works from anywhere.

If NAT loopback isn’t available and split-horizon is the only option:

  1. Restrict scope. Don’t split-horizon the entire zone. Carve out the names that need it (app.example.com, intranet.example.com) and leave the rest in a single global view.
  2. Configure BIND views in /etc/named.conf. cPanel’s named.conf template doesn’t auto-create views; you have to add them manually and protect against cPanel’s next zone-config rewrite. The protected path: edit /etc/named.conf.include or /etc/cpanel/templates/named.conf.local so cPanel preserves the change.
  3. Keep the two zone files in sync for records that should match (MX, TXT, NS, SOA). Use a script that generates the internal zone from the external by replacing only the specific A records.
  4. Communicate the limitation to users. Document that the internal view works only on the office network; from home or VPN, the external view applies. Users who hit “site doesn’t work” from home know to check the URL.
  5. Set a low TTL (60-300) on the records that differ, so browser caches age out quickly when users move between networks.
  6. Reconsider periodically. Six months in, count the support tickets caused by split-horizon vs the benefit. The architecture often gets retired in favour of a single public answer plus NAT loopback or VPN-with-routing-only-no-DNS.

For genuinely internal-only names (an internal Active Directory zone, a developer-only test environment), use a different domain entirely (example.internal) and serve it from a private resolver. That avoids the split-horizon problem because the name simply doesn’t exist publicly.

Stack Harbor advises on DNS topology including split-horizon trade-offs as part of deployment management.