Kokil Thapa - Professional Web Developer in Nepal
Freelancer Web Developer in Nepal with 15+ Years of Experience

Kokil Thapa is an experienced full-stack web developer focused on building fast, secure, and scalable web applications. He helps businesses and individuals create SEO-friendly, user-focused digital platforms designed for long-term growth.

Set Up a BIND DNS Server on Linux

By Kokil Thapa | Last reviewed: September 2026

When you need full control over hostname resolution, you set up a BIND DNS server on Linux instead of relying only on a registrar panel. Managed DNS from Cloudflare or your domain registrar works fine for most sites. Self-hosted BIND makes sense when you run private zones, staging hostnames, split-horizon routing, or internal service discovery on a VPS. I've deployed BIND on Ubuntu servers for client infrastructure where Laravel apps, mail, and staging environments all needed predictable internal names. This guide walks through a working authoritative setup you can copy on Ubuntu 22.04 or 24.04.

When should you set up a BIND DNS server on Linux?

Not every project needs its own nameserver. A registrar or CDN DNS panel handles public records with less ops overhead. BIND earns its place when requirements go beyond simple A and CNAME entries.

Common reasons to run BIND on a Linux box:

  • Private internal zones — resolve db.internal or api.staging without exposing names publicly.
  • Split-horizon DNS — return a private IP to office clients and a public IP to everyone else.
  • Lab and staging — mirror production DNS locally before cutover.
  • Learning and compliance — some teams must host DNS inside their own network boundary.
  • Backup resolver — a local caching resolver reduces upstream dependency during outages.

If you only publish a marketing site and one API, stick with managed DNS. Pair that with our guide on DNS record types explained and domain registration and hosting instead of running BIND.

BIND DNS Server Architecture on LinuxClientBrowser / appBIND9named daemonZone filesdb.example.comAuthoritativeOwns example.comCachingForwards upstreamRecursiveFull resolverPort 53 UDP/TCP — configure firewall before going liveSee ufw rules and systemd service management on your host
How clients reach a BIND DNS server on Linux — authoritative, caching, and recursive roles

BIND9 is the standard implementation on Debian and Ubuntu. The daemon is called named. Configuration lives under /etc/bind/. Official documentation from ISC BIND remains the authoritative reference for directives and security advisories.

How do you install BIND9 on Ubuntu or Debian?

Start on a clean Ubuntu 22.04 or 24.04 VPS with a static IP. DNS servers need stable addresses. Floating IPs work, but document the mapping clearly.

Install packages

sudo apt update
sudo apt install -y bind9 bind9utils bind9-doc dnsutils

The dnsutils package gives you dig, nslookup, and host. You will use dig constantly during testing. On a fresh Ubuntu server setup, confirm the hostname resolves before touching BIND.

Check the default service

sudo systemctl enable named
sudo systemctl start named
sudo systemctl status named

Ubuntu may use the unit name bind9 on some images. Run systemctl list-units | grep bind if status fails. Learn service control patterns in our systemd guide for Linux services.

Set the server identity

Edit /etc/bind/named.conf.options and set a forwarders block only if this host acts as a caching resolver. For a pure authoritative server, leave recursion off — covered in the hardening section.

Set Up a BIND DNS Server — Step Flowapt installnamed.conf.local zonesZone filedb.example.comFirewallport 53digValidation commands after each stepnamed-checkconf /etc/bind/named.confnamed-checkzone example.com /etc/bind/db.example.comsystemctl reload nameddig @127.0.0.1 example.com A +short
Installation and configuration pipeline to set up a BIND DNS server on Linux

How do you configure named.conf and zone files?

Ubuntu splits BIND config into include files. You rarely edit the top-level named.conf directly. Add zones in /etc/bind/named.conf.local.

Declare a forward zone

Replace example.com and IP addresses with your domain and server IP. This example uses 203.0.113.10 as the VPS address (RFC 5737 documentation range).

zone "example.com" {
    type master;
    file "/etc/bind/db.example.com";
};

Append that block to named.conf.local. Then create the zone file at /etc/bind/db.example.com:

$TTL    86400
@       IN      SOA     ns1.example.com. admin.example.com. (
                        2026091001      ; serial (YYYYMMDDnn)
                        3600            ; refresh
                        1800            ; retry
                        604800          ; expire
                        86400 )         ; minimum

        IN      NS      ns1.example.com.
ns1     IN      A       203.0.113.10
@       IN      A       203.0.113.10
www     IN      A       203.0.113.10
api     IN      A       203.0.113.10
mail    IN      A       203.0.113.10
@       IN      MX      10 mail.example.com.

Increment the serial every time you edit the zone. BIND slaves use serial numbers to detect changes. A forgotten serial bump is a classic production mistake.

Add a reverse zone (optional but useful)

Reverse DNS maps IP back to hostname. Mail servers often need it. For 203.0.113.10, the reverse zone name is 113.0.203.in-addr.arpa.

zone "113.0.203.in-addr.arpa" {
    type master;
    file "/etc/bind/db.203.0.203";
};

Zone file content:

$TTL 86400
@   IN  SOA ns1.example.com. admin.example.com. (
            2026091001 3600 1800 604800 86400 )
    IN  NS  ns1.example.com.
10  IN  PTR mail.example.com.

Allow queries in named.conf.options

Find the options block and restrict who may query. Never leave allow-query { any; } on a public resolver without rate limits.

options {
    directory "/var/cache/bind";
    recursion no;
    allow-query { any; };
    listen-on { any; };
    dnssec-validation auto;
};

For an internal-only authoritative server, replace any with your office CIDR or VPN range. Pair this with UFW firewall rules for web servers — DNS uses port 53 on both UDP and TCP.

BIND Zone File Record LayoutSOA — serial, refresh, retry, expire, minimum TTLNS — nameserver delegationA / AAAA — host to IPCNAME — alias recordsMX — mail routingTXT — SPF, DKIM, verifyPTR — reverse DNSValidate syntax before reload — named-checkzone catches typos early
Core record types inside a BIND zone file when you set up a BIND DNS server on Linux

Validate before reload:

sudo named-checkconf
sudo named-checkzone example.com /etc/bind/db.example.com
sudo systemctl reload named

Fix every error reported by those commands. BIND fails silently in odd ways when zone syntax is wrong. Use our regex tester to debug complex TXT record patterns if needed.

How do you test and delegate DNS to your BIND server?

Local tests prove BIND works. Delegation proves the internet trusts your server.

Query locally with dig

dig @127.0.0.1 example.com A +short
dig @127.0.0.1 www.example.com A +short
dig @203.0.113.10 example.com NS +short

Expect clean answers with no REFUSED or SERVFAIL status. Query from a remote machine too:

dig @203.0.113.10 example.com A

If remote queries time out, check UFW, cloud security groups, and whether BIND listens on the public interface.

Register glue records at your registrar

When your nameserver hostname lives inside the zone it serves, you need glue records. At your registrar, set:

  1. NS records pointing to ns1.example.com.
  2. A glue record mapping ns1.example.com to 203.0.113.10.
  3. Remove old NS entries if migrating from managed DNS.
  4. Wait for TTL expiry — often 24 to 48 hours, sometimes faster.

During migration, lower TTLs at the old provider a day ahead. That speeds cutover. Our article on cross-cloud DNS and traffic routing covers failover patterns when you mix BIND with CDN DNS.

Compare managed DNS vs self-hosted BIND

CriteriaManaged DNS (registrar/CDN)Self-hosted BIND on Linux
Setup timeMinutes via web panelHours including hardening and tests
CostFree tier or ~USD 5–20/monthVPS cost only — Rs 500–2,000/month (~USD 4–15)
Private zonesLimited or paid featureFull control on internal networks
DDoS protectionBuilt into major providersYou must add firewall and upstream filtering
Ops burdenLow — provider handles patchesYou patch BIND and monitor uptime
Best fitPublic websites, eCommerce, APIsInternal infra, staging, split DNS

On production Laravel stacks I maintain, public DNS stays managed. BIND handles staging hostnames and internal service names. That split keeps booking platforms and legal-tech portals reachable while dev environments stay isolated.

How do you secure and maintain a BIND DNS server?

An open recursive resolver on the public internet gets abused within hours. Attackers use it for amplification DDoS. Lock it down before port 53 faces the world.

Disable recursion on authoritative servers

recursion no;
allow-recursion { none; };

Put those in named.conf.options. Authoritative servers answer only for zones they own. Caching and forwarding belong on a separate internal resolver.

Restrict queries and transfers

allow-query { 203.0.113.0/24; 10.0.0.0/8; };
allow-transfer { none; };

Block zone transfers unless you run secondary nameservers. Use TSIG keys if slaves are required — see the BIND 9 Administrator Reference Manual for key generation.

Keep BIND patched

sudo apt update && sudo apt upgrade bind9
sudo systemctl restart named

Subscribe to ISC security advisories. DNS software bugs get exploited quickly. Combine patching with Ubuntu server security best practices and server hardening guides.

Monitor and back up zone files

Zone files are plain text. Back them up with your normal server backup routine. Our guides on Ubuntu server backup strategies and automated rsync backups apply directly.

Watch query volume with Netdata or similar. A sudden spike often means your resolver was left open. Read Linux server monitoring with Netdata for zero-config metrics.

Managed DNS vs BIND — Decision GuideNeed custom DNS?Public websiteUse managed DNSPrivate zonesRun BIND internalSplit horizonBIND on LinuxProduction checklist for BINDrecursion off · firewall port 53 · serial increments · dig tests · backupsPair with SSL via Certbot after A records propagate
Choose managed DNS or set up a BIND DNS server on Linux based on public vs internal needs

After DNS propagates, issue certificates with Let's Encrypt and Certbot. Certificate validation depends on correct A and CNAME records. Wrong NS delegation breaks HTTPS before your web server ever gets traffic.

For API endpoints behind CDNs, remember that DNS TTL affects cache behaviour. See Cloudflare DNS cache bypass for API endpoints when mixing edge DNS with origin BIND zones.

Key Takeaways

  • Install bind9 and dnsutils, then define zones in /etc/bind/named.conf.local with matching zone files under /etc/bind/.
  • Always run named-checkconf and named-checkzone before systemctl reload named.
  • Disable recursion and restrict allow-query on public authoritative servers to prevent abuse.
  • Open UDP and TCP port 53 in UFW and your cloud security group, then verify with dig @your-ip domain.com from a remote host.
  • Register NS and glue records at your registrar; bump zone serial numbers on every edit.
  • Use managed DNS for public sites and BIND for private, staging, or split-horizon zones — not both fighting over the same records.

People Also Ask

What is the difference between BIND authoritative and recursive modes?

An authoritative server answers only for zones it hosts — example.com records live in its zone files. A recursive resolver chases queries across the internet on behalf of clients. Production authoritative servers should set recursion no. Mixing both roles on one public IP invites abuse.

Which port does BIND use on Linux?

BIND listens on port 53 for both UDP and TCP. Most queries use UDP. Large responses and zone transfers use TCP. Firewalls must allow both protocols. Cloud providers often block port 53 outbound on consumer tiers — confirm your VPS plan allows inbound 53.

Can I run BIND alongside Apache or Nginx on the same server?

Yes. DNS and web serving use different ports. A single small VPS can run BIND, Nginx, and PHP-FPM together. Separate concerns are cleaner at scale — DNS on dedicated low-traffic hosts, web on application servers. For typical client projects, co-location on one Ubuntu box is fine.

How long does DNS propagation take after pointing NS to BIND?

Propagation depends on TTL values at the previous provider. With TTL set to 300 seconds before migration, most resolvers pick up new NS records within an hour. Default TTLs of 86400 seconds mean up to 24 hours. Test with dig +trace example.com to follow delegation from root to your server.

Deploy DNS with confidence

You now have the full path to set up a BIND DNS server on Linux — install, zone files, validation, delegation, and hardening. Start in a staging VPC or lab VPS before touching production NS records. Keep managed DNS for public traffic unless you have a clear reason to self-host.

Need help wiring DNS into a broader server stack — Laravel apps, mail, SSL, monitoring, and backups? Support and maintenance and testing and optimization cover the full lifecycle. For greenfield infrastructure, see planning and research services or contact us to discuss your setup. Browse the home page, about page, services overview, portfolio, blog, and customer reviews for related work. Operators in Nepal should also read how to secure your website and server in Nepal and CIS benchmarks for server hardening. Use the JSON formatter when inspecting API responses from DNS automation tools, and base64 encoder for encoding TSIG keys during advanced BIND configurations.

Frequently Asked Questions

Use BIND when you need private internal zones, split-horizon routing, staging hostnames, lab mirrors before cutover, compliance inside your network boundary, or a local caching backup resolver. Registrar and CDN panels handle simple public A and CNAME records with far less ops work. If you only publish a marketing site and one API, managed DNS is the practical choice. On production Laravel stacks I maintain, public DNS stays managed while BIND handles staging and internal service names.

Start on a clean VPS with a static IP, then run apt update and install bind9, bind9utils, bind9-doc, and dnsutils. The dnsutils package gives you dig for testing. Enable and start the named service with systemctl — some Ubuntu images use the unit name bind9 instead, so grep bind units if status fails. Confirm the hostname resolves before editing configuration. For a pure authoritative server, leave forwarders out of named.conf.options until you decide whether this host also caches.

Ubuntu splits BIND configuration into include files under /etc/bind/. You rarely edit the top-level named.conf directly. Declare forward and reverse zones in /etc/bind/named.conf.local with type master and a file path pointing to each zone file. Create matching zone files such as /etc/bind/db.example.com with SOA, NS, A, and MX records. Query permissions and recursion settings live in /etc/bind/named.conf.options. Always validate with named-checkconf and named-checkzone before reloading named.

A working authoritative zone needs a SOA record with a serial in YYYYMMDDnn format, refresh, retry, expire, and minimum values, plus an NS record pointing to your nameserver hostname. Add A records for ns1, www, api, and mail at your VPS IP, and an MX record targeting mail.example.com. Replace example.com and IP addresses with your real domain and server address. The article uses 203.0.113.10 as a documentation-range example. Bump the serial every time you edit the zone file.

BIND slaves and secondary nameservers compare SOA serial numbers to detect zone changes. If you edit A, MX, or TXT records but forget to increment the serial, downstream servers may keep serving stale data while local queries look correct. That mismatch causes confusing cutover bugs during migrations. Increment the serial in YYYYMMDDnn format on every change, then run named-checkzone and reload named. It is one of the most common production mistakes I see on self-hosted DNS.

Reverse DNS maps an IP address back to a hostname and is optional but useful, especially for mail servers. For IP 203.0.113.10, declare a reverse zone named 113.0.203.in-addr.arpa in named.conf.local pointing to a zone file such as /etc/bind/db.203.0.203. Inside that file, add SOA and NS records, then a PTR record mapping the last octet to mail.example.com. Validate the reverse zone with named-checkzone the same way you validate forward zones before reloading named.

BIND listens on port 53 for both UDP and TCP. Most queries use UDP; large responses and zone transfers use TCP. Open both in UFW and your cloud security group.

Run named-checkconf on the full configuration and named-checkzone against each zone file — fix every error before reload. Query locally with dig @127.0.0.1 for your domain A and www records, and dig @your-server-ip for NS records. Expect clean answers with no REFUSED or SERVFAIL status. Test from a remote machine too with dig @your-ip example.com A. If remote queries fail while local ones succeed, the problem is usually firewall rules, cloud security groups, or BIND not listening on the public interface.

Glue records are required when your nameserver hostname lives inside the zone it serves — for example ns1.example.com authoritative for example.com. At your registrar, set NS records pointing to ns1.example.com and add a glue A record mapping ns1.example.com to your VPS IP such as 203.0.113.10. Remove old NS entries if migrating from managed DNS. Without glue, resolvers cannot reach your server to start delegation. Local dig tests can pass while public resolution still fails until glue and NS records propagate.

Managed DNS from a registrar or CDN typically costs nothing on a free tier or roughly USD 5–20 per month, with minutes of setup and built-in DDoS protection. Self-hosted BIND costs only your VPS — roughly Rs 500–2,000 per month, about USD 4–15 — but needs hours for hardening, testing, and ongoing patches. Managed DNS suits public websites, eCommerce, and APIs. BIND fits private zones, staging hostnames, split-horizon routing, and internal infrastructure where you need full control inside your network boundary.

An authoritative server answers only for zones it hosts in local zone files. A recursive resolver chases queries across the internet on behalf of clients. Set recursion no on public authoritative servers.

An open recursive resolver gets abused for amplification DDoS within hours. Set recursion no and allow-recursion { none; } in named.conf.options so the server answers only for zones it owns. Restrict allow-query to your office CIDR or VPN range instead of any on internal authoritative hosts. Set allow-transfer { none; } unless you run secondary nameservers — use TSIG keys if slaves are required. Keep BIND patched with apt upgrade bind9, subscribe to ISC security advisories, back up plain-text zone files, and watch query volume for sudden spikes indicating an open resolver.

Propagation depends on TTL at the previous provider. With TTL lowered to 300 seconds before migration, most resolvers pick up new NS records within about an hour. Default TTLs of 86400 seconds can mean up to 24 hours.

Yes. DNS and web serving use different ports, so a single small VPS can run BIND alongside Nginx and PHP-FPM together without conflict. For typical client projects I work on, co-locating both on one Ubuntu box is fine and keeps costs down. At larger scale, separating DNS onto dedicated low-traffic hosts and keeping web on application servers is cleaner operationally. The article assumes this combined layout is normal for staging and internal infrastructure, not high-traffic public resolver workloads.

If dig @127.0.0.1 works but dig from another machine to your public IP times out, check three layers. First, confirm UFW allows inbound UDP and TCP port 53. Second, verify your cloud provider security group permits the same — some VPS plans block port 53 on consumer tiers. Third, confirm named.conf.options listen-on includes the public interface and that named reloaded cleanly after edits. Also confirm your VPS plan allows inbound port 53 at the provider level before spending time on zone file syntax.

Share this article

0 Comments

Leave a comment

Your email is not published. Comments appear once they have been read. Sign in to have your details filled in.

Quick Contact Options
Choose how you want to connect me: