keepcalculator

06 Numbers and Powers

Custom Name Servers for VPS: Setup Guide

Card No. 06·70483 · Updated · Standard formula, shown below

Setting up custom name servers on your VPS lets you use your own domain (like ns1.yourdomain.com) instead of your hosting provider’s default name servers. This gives you full control over DNS records and a more professional look. You’ll need a VPS with a static IP address, a registered domain, and root or sudo access to your server.

What You’ll Need

  • A VPS with a static public IP address (IPv4 and optionally IPv6)
  • A registered domain name (e.g., yourdomain.com)
  • Root or sudo access to the VPS (to install and configure DNS software)
  • SSH client (like PuTTY on Windows, or Terminal on macOS/Linux)
  • Access to your domain registrar’s control panel (to set glue records)

Step-by-Step

  1. Choose DNS software. The most common is BIND (named). On Debian/Ubuntu, install it with sudo apt update && sudo apt install bind9. On CentOS/RHEL, use sudo yum install bind.
  2. Get your VPS IP address. Run ip addr show or curl ifconfig.me to find your public IP. Note it down.
  3. Configure BIND to listen on your public IP. Edit /etc/bind/named.conf.options (Debian/Ubuntu) or /etc/named.conf (CentOS). Set listen-on port 53 { any; }; and allow-query { any; }; (or restrict to specific IPs if you prefer). Also set recursion no; if you only want to serve authoritative DNS.
  4. Create a zone file for your domain. Add a zone definition in named.conf.local (Debian/Ubuntu) or named.conf (CentOS). For example:
    zone "yourdomain.com" {
        type master;
        file "/etc/bind/db.yourdomain.com";
    };
  5. Create the zone file. Copy the template: sudo cp /etc/bind/db.local /etc/bind/db.yourdomain.com. Edit it to include your domain’s SOA, NS records, and A records. At minimum, add:
    @       IN SOA ns1.yourdomain.com. admin.yourdomain.com. (
            2025010101 ; serial
            7200       ; refresh
            3600       ; retry
            1209600    ; expire
            86400 )    ; minimum
    @       IN NS  ns1.yourdomain.com.
    @       IN NS  ns2.yourdomain.com.
    ns1     IN A   YOUR_VPS_IP
    ns2     IN A   YOUR_VPS_IP

    Replace YOUR_VPS_IP with your actual IP. If you have a second IP, use it for ns2; otherwise, you can use the same IP for both (though it’s not recommended for redundancy).

  6. Check the zone file syntax. Run sudo named-checkzone yourdomain.com /etc/bind/db.yourdomain.com. Fix any errors.
  7. Restart BIND. Use sudo systemctl restart bind9 (Debian/Ubuntu) or sudo systemctl restart named (CentOS). Check status with sudo systemctl status bind9 (or named).
  8. Open port 53 in the firewall. If you use ufw: sudo ufw allow 53. If you use firewalld: sudo firewall-cmd --add-service=dns --permanent && sudo firewall-cmd --reload.
  9. Set glue records at your registrar. Log into your domain registrar’s control panel. Find the option for “Name Servers” or “DNS Management”. You’ll need to add “custom name servers” or “glue records”. For each name server (ns1 and ns2), enter the hostname (e.g., ns1.yourdomain.com) and the IP address (your VPS IP). Save the changes.
  10. Update your domain’s name servers. At the registrar, change the domain’s name servers from the default ones to ns1.yourdomain.com and ns2.yourdomain.com.
  11. Wait for propagation. DNS changes can take up to 24-48 hours to propagate worldwide, though it’s often faster. Use a tool like dig or an online DNS checker to verify.
  12. Test your name servers. Run dig @YOUR_VPS_IP yourdomain.com NS to see if your server responds correctly. Also test with dig @YOUR_VPS_IP yourdomain.com A.

Common Mistakes

  • Using the same IP for both NS records when you don’t have a second IP. It works, but creates a single point of failure.
  • Forgetting to open port 53 in the firewall, which makes the server unreachable for DNS queries.
  • Incorrect zone file syntax (missing trailing dots, wrong TTL). Always run named-checkzone.
  • Not updating the serial number when you change the zone file. BIND will not reload the zone if the serial is unchanged.
  • Setting glue records to the wrong IP (e.g., using the registrar’s IP instead of your VPS).
  • Forgetting to set the domain’s name servers to your custom ones after creating glue records.

Tips

  • Use a second VPS or IP for ns2 to provide redundancy. If you can’t, you can use a free DNS hosting service as a secondary.
  • Keep your zone file serial number in a date-based format (YYYYMMDDnn) to easily track changes.
  • Set up DNSSEC for security, but it’s advanced. Start with basic setup first.
  • Monitor your name server with tools like Nagios or UptimeRobot to ensure it’s always up.
  • Use a low TTL (like 300 seconds) for records you might change often, then increase it later.

Troubleshooting

  • DNS queries time out: Check that BIND is running (sudo systemctl status bind9), that port 53 is open (sudo netstat -tulpn | grep :53), and that your firewall allows it.
  • “Server failed” or SERVFAIL: Check the zone file for errors with named-checkzone. Also check BIND logs (sudo tail -f /var/log/syslog or /var/log/messages).
  • Glue records not working: Ensure you’ve added them correctly at the registrar. It may take a few hours to propagate. Use dig +trace yourdomain.com NS to see the delegation path.
  • Your domain doesn’t resolve: Verify that the domain’s name servers are set to ns1 and ns2. Use whois yourdomain.com to see the current name servers.
  • Can’t query your own server from outside: Check that BIND is listening on the public IP, not just localhost. Also check that your VPS provider doesn’t block port 53 (some do).

Frequently Asked Questions

Can I use the same IP for both ns1 and ns2?

Technically yes, but it’s not recommended because if that IP goes down, both name servers fail. For a production setup, use two different IPs (e.g., from two VPSs).

How long does DNS propagation take?

Typically 24-48 hours, but often much faster (a few hours). The TTL you set on your records affects how long resolvers cache them.

Do I need to run my own DNS server to have custom name servers?

Yes, you need a DNS server that is authoritative for your domain. The custom name servers are the hostnames of that server.

Can I use a subdomain like dns.mydomain.com for name servers?

Yes, you can use any subdomain, but the glue records must be set at the registrar to point to your VPS IP.

What is a glue record?

It’s a record at the registrar that maps your name server hostname (e.g., ns1.yourdomain.com) to its IP address. It’s needed to avoid circular dependency when resolving the name server itself.

Is it safe to run my own DNS server?

Yes, but you must keep the software updated and configure it securely (e.g., disable recursion if not needed). Unpatched DNS servers can be vulnerable to attacks.

Related

Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.

More cards in this drawer

The whole Numbers and Powers drawer →