How to create a DNS record in Linux (Debian/Ubuntu)

Creating a DNS record on Linux usually means configuring a DNS server (most commonly BIND) rather than just running a single command. Here’s a clear, practical way to do it.

If BIND is not installed yet, then install BIND.

On Linux terminal, type:

sudo apt update
sudo apt install bind9

Once BIND is installed, we can now proceed to configuring the Zone File.

DNS records live inside zone files.

Check /etc/bind/named.conf.local (or sometimes named.conf):

You can use File Manager and locate the file or you can use command:

sudo nano /etc/bind/named.conf.local

Add your domain. Example:

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

The important part is the file path. That’s your zone file.

After that, create a Zone File.

sudo cp /etc/bind/db.local /etc/bind/db.example.com

Edit it:

sudo nano /etc/bind/db.example.com

Add DNS Records.

$TTL 86400
@ IN SOA ns1.example.com. admin.example.com. (
    2026032100 ; Serial
    3600 ; Refresh
    1800 ; Retry
    604800 ; Expire
    86400 ) ; Negative Cache TTL@ IN NS ns1.example.com.
@ IN NS ns1.example.com. ; Name Server

@ IN A 203.0.113.10 ; A Record (domain → IP)
www IN A 203.0.113.10

Other DNS record:

There are other DNS records you can add, here are common examples:

A record

app IN A 203.0.113.20

AAAA (IPv6)

@ IN AAAA 2001:db8::20
app IN AAAA 2001:db8::20

CNAME (alias)

app IN CNAME www.example.com.

⚠️ CNAME must point to a FQDN and end with a dot.

MX record (mail server)

@ IN MX 10 mail.example.com.
mail IN A 203.0.113.20

TXT record

@ IN TXT "v=spf1 ip4:203.0.113.10 -all"

Check your syntax (do not skip this)

Run:

sudo named-checkzone example.com /etc/bind/db.example.com

You want:

OK

Also check global config:

sudo named-checkconf

Reload BIND

Finally, apply the changes:

sudo systemctl reload bind9

Testing

From the server or another machine:

dig example.com

or

nslookup example.com

Leave a Reply