SmatrCGI Logo
  
Home News Products Customers Contact us
     
Web Development

About
Portfolio
Prices
Contact us

Web Design

About
Portfolio
Prices
Contact us

Translating

About
Languages
Prices
Contact us


MyDNS name server ***quick*** HOWTO

MyDNS name server ***quick*** HOWTO


MyDNS is a fast name server for *nix that uses MySQL to store zones and hosts information. It's ideal solution if you develop automatic systems that need to update DNS information often or if you have a lot of domains and hosts. Currently, we use MyDNS name server on single server to support over 500,000 hosts and approximatelly 1500 domains. Basically, you can have all kind of records within it including MX, A, NS records. Since MySQL database software supports replications, you can setup a replication on any another server and use MyDNS software as secondary name server.

Basic configuration

Default configuration file for MyDNS server is /etc/mydns.conf. Here's an example of typical configuration file:

    # Database information
    
    db-host = localhost          	# MySQL server hostname
    db-user = mydns              	# MySQL username
    db-password = top_secret_pass	# MySQL password
    database = mydns                    # MyDNS database name

    # GENERAL OPTIONS

    user = mydns	# Run with the permissions of this user
    group = mydns	# Run with the permisisons of this group
    listen = *		# IP addresses to listen. You can use comma-limited IP addresses. 	

    # CACHE OPTIONS

    cache-size = 600000		# Maximum number of elements stored in thecache
    cache-expire = 300		# Number of seconds after which cached data expires


    # ESOTERICA

    log = LOG_DAEMON			# Facility to use for program output (LOG_*/stderr)
    pidfile = /var/run/mydns.pid	# Path to PID file
    timeout = 30			# Number of seconds after which queries time out
    multicpu = 4			# Number of CPUs installed on your system
    allow-axfr = yes			# Should AXFR be enabled?
    allow-tcp = no			# Should TCP be enabled?
    soa-table = mydns_soa		# Name of table containing SOA records
    rr-table  = mydns_users		# Name of table containing RR data
    ptr-table = mydns_ptr		# Name of table containing PTR records

    
*Note: Never enable TCP connections if you don't want your MyDNS server to become frozen by DOS attacks.

How to add zones and hosts into MyDNS configuration

First, we need to add zone into MySQL. Just run mysql command prompt on your server and domain 'domain.com' with ns1.domain.com as nameserver and admin@domain.com as admin's email.
    mysql> insert into mydns_soa(origin,ns,mbox,serial) values('domain.com.', 'ns1.domain.com','admin@domain.com',1);
    
To add hosts into database we need to know what zone ID our domain has:
    mysql> select id from mydns_soa where origin='domain.com.';	
    mysql>
	+----+
	| id |
	+----+
	| 1 |
	+----+
	1 row in set (0.00 sec)

    
Lets add some hosts and special records:
    # base domain, ie domain.com
    mysql> insert into mydns_users(zone, name,type,data) values(1,'','A','10.20.30.41');	
    
    # ie www.domain.com    
    mysql> insert into mydns_users(zone, name,type,data) values(1,'www','A','10.20.30.41');	
    
    # name server
    mysql> insert into mydns_users(zone, name,type,data) values(1,'ns1','A','10.20.30.41');	
    
    # mx01.domain.com as primary mail hub with priority 5
    mysql> insert into mydns_users(zone, name,type,data,aux) values(1,'','MX','mx01',5);	
    
    # mx02.domain.com as primary mail hub with priority 10
    mysql> insert into mydns_users(zone, name,type,data,aux) values(1,'','MX','mx02',10);	
    
    # mx01.domain.com mail hub.    
    mysql> insert into mydns_users(zone, name,type,data) values(1,'mx01','A','10.20.30.41');	  
    
    # mx02.domain.com mail hub.      
    mysql> insert into mydns_users(zone, name,type,data) values(1,'mx02','A','10.20.31.41');	
    

Tips

  • if you need to build 3rd level domains you can insert 'subdomain.domain.com' into SOA table and add records like 'host.subdomain.domain.com' into RR table.
  • Wildcard records like *.domain.com are supported as well.
  • DNS Roard-Robin aka load balancing by DNS
    You can insert several records with the same name with different ip addresses to balance bandwidth between them:
        mysql> insert into mydns_users(zone, name,type,data) values(1,'www','A','10.20.30.41');	# ie www.domain.com
        mysql> insert into mydns_users(zone, name,type,data) values(1,'www','A','10.20.30.42');	# ie www.domain.com
        mysql> insert into mydns_users(zone, name,type,data) values(1,'www','A','10.20.30.43');	# ie www.domain.com
        
  • And last, very important tip - NEVER forget where zone=xx when you run your updating SQL statement :)


© Copyright 1999 - 2004 SmartCGI, Inc. All Rights Reserved.