How to Configure DNS Delegation for Subdomains: A Technical Guide for Programmers


1 views

When you want to manage subdomains through your own DNS server while keeping the parent domain managed by your hosting provider, you need to implement proper DNS delegation. This involves creating NS (Name Server) records at your provider's DNS that point specific subdomains to your own DNS servers.

Here's how to properly set up delegation for ftp.econemon.com while keeping econemon.com at your provider:

; At your hosting provider's DNS zone file for econemon.com
econemon.com.     IN  A      192.0.2.1
ftp.econemon.com. IN  NS     ns1.yourdnsserver.com.
ftp.econemon.com. IN  NS     ns2.yourdnsserver.com.
ns1.yourdnsserver.com. IN A  203.0.113.1
ns2.yourdnsserver.com. IN A  203.0.113.2

To route undefined subdomains to your main domain's IP address, you can use wildcard records at your hosting provider:

*.econemon.com.   IN  A      192.0.2.1

For failover scenarios where your DNS server becomes unavailable, configure appropriate TTL values and consider these approaches:

; At your own DNS server (BIND configuration example)
$TTL 300  ; 5-minute TTL for quick failover
ftp.econemon.com. IN  A      198.51.100.1

The resolution process works like this:

  1. Client queries for ftp.econemon.com
  2. Root servers direct to .com servers
  3. .com servers point to your hosting provider's nameservers
  4. Provider's NS records direct ftp subdomain to your DNS servers
  5. Your DNS server responds with the actual A record

For those using common DNS server software, here are configuration snippets:

# BIND named.conf zone configuration
zone "ftp.econemon.com" {
    type master;
    file "/etc/bind/db.ftp.econemon.com";
    allow-transfer { secondary-ip; };
};

Here's the corresponding zone file:

; db.ftp.econemon.com
$TTL 3600
@       IN  SOA  ns1.yourdnsserver.com. admin.econemon.com. (
                  2023081501 ; serial
                  3600       ; refresh
                  900        ; retry
                  2419200    ; expire
                  300 )      ; minimum TTL

        IN  NS   ns1.yourdnsserver.com.
        IN  NS   ns2.yourdnsserver.com.

ftp     IN  A    198.51.100.1

DNS delegation allows you to distribute authority for different parts of your domain hierarchy. In your scenario with econemon.com, you want the parent domain managed by your hosting provider while handling ftp.econemon.com through your own DNS service.

When a client queries for ftp.econemon.com, the resolution works like this:

  1. The recursive resolver checks root and TLD (.com) servers
  2. It queries your domain's authoritative nameservers (hosting provider)
  3. Your hosting provider's DNS responds with either:
    • The IP address if they're authoritative
    • A referral to your subdomain's nameservers if delegated

To delegate ftp.econemon.com to your own nameserver:


; At your hosting provider's DNS configuration
econemon.com.      IN  NS    ns1.hostingprovider.com.
econemon.com.      IN  A     192.0.2.1
ftp.econemon.com.  IN  NS    ns1.yourdnsserver.com.
ftp.econemon.com.  IN  NS    ns2.yourdnsserver.com.

For wildcard subdomains to resolve to your main domain:


; In your hosting provider's zone file
*.econemon.com.    IN  A     192.0.2.1

To implement DNS failover to your main domain IP when your nameserver is down:


; In your hosting provider's zone file
ftp.econemon.com.  IN  A     192.0.2.1  ; Fallback IP
ftp.econemon.com.  IN  NS    ns1.yourdnsserver.com.  ; Primary
ftp.econemon.com.  IN  NS    ns2.yourdnsserver.com.  ; Secondary

Here's a sample configuration for your own nameserver (BIND):


// named.conf
zone "ftp.econemon.com" {
    type master;
    file "/etc/bind/db.ftp.econemon.com";
    allow-transfer { secondary-ip; };
};

// db.ftp.econemon.com
$TTL 86400
@ IN SOA ns1.yourdnsserver.com. admin.econemon.com. (
    2024030101 ; serial
    3600       ; refresh
    900        ; retry
    604800     ; expire
    86400      ; minimum TTL
)

@        IN  NS    ns1.yourdnsserver.com.
@        IN  NS    ns2.yourdnsserver.com.
@        IN  A     192.0.2.42  ; Your FTP server IP
www      IN  CNAME @

After setup, verify with:


dig +trace ftp.econemon.com
dig @ns1.yourdnsserver.com ftp.econemon.com