Adding new domains to DNS servers from the shell

Expertise level: Medium

This procedure is for Bind or named, two popular DNS servers.

To add a new domain, you need to edit two files related to Bind DNS server.

Adding an entry to Named.conf:

  1. Login with SSH as root.
  2. Open the file /etc/named.conf in any text editor.
  3. At the end of the file, add the zone entry for domain.com in the following format:
zone "domain.com" {
type master;
file "/var/named/domain.com.db";
};

Creating the DB Record:

/var/named/domain.com.db is the path to the DB record file where you can add the Address records and MX records and all other DNS records related to domain.com.

  1. Open the file /var/named/domain.com.db for editing in a text editor.
  2. You can copy and paste the contents of the example below to the file (Edit each of the records according to what is needed for domain.com. Replace the IP address 10.10.10.10 with the domain.com  IP address)
  3. Save and exit the text editor.
  4. Type this command to reload DNS server:
rndc reload

Example of /var/named/domain.com.db file:

; Zone file for domain.com
$TTL 14400
domain.com.   86400   IN      SOA     ns1.domain.com.   host.domain.com.   (
                                                2012031401 ;Serial Number
                                                86400 ;refresh
                                                7200 ;retry
                                                3600000 ;expire
                                                86400 ;minimum
        )

domain.com.   86400   IN      NS      ns1.domain.com.
domain.com.   86400   IN      NS      ns2.domain.com.


domain.com.   14400   IN      A       10.10.10.10

localhost       14400   IN      A       127.0.0.1

domain.com.   14400   IN      MX      0       domain.com.

mail    14400   IN      CNAME   domain.com.
www     14400   IN      CNAME   domain.com.
ftp     14400   IN      CNAME   domain.com.
webmail 14400   IN      A       10.10.10.10

For more information about how to manage the Bind DNS service, please consult the following links:

http://centos.org/docs/2/rhl-rg-en-7.2/s1-bind-configuration.html

http://www.cyberciti.biz/faq/tag/bind-9/

Have more questions? Submit a request

0 Comments

Article is closed for comments.
Powered by Zendesk