Running A MySQL-Based DNS Server: MyDNS - Page 2

2 Install A Web Interface To MyDNS

In the following steps I assume you use Debian Sarge; the default Debian Apache document root is /var/www so I will install the web interfaces here. Furthermore I assume that the host name is ns1.example.com.

2.1 phpMyAdmin

phpMyAdmin has been installed at the beginning of this tutorial (apt-get install mysql-server mysql-client libmysqlclient12-dev phpmyadmin), so you should be able to access it under http://ns1.example.com/phpmyadmin. Then select the database mydns, and you should see the tables rr and soa. Have a look here for an explanation of the database structure/fields, etc.: http://mydns.bboy.net/doc/html/mydns_8.html#SEC8

2.2 The Original MyDNS Web Interface

To install the original MyDNS web interface (comes with the MyDNS sources that should still be in the /tmp directory), do this:

cp /tmp/mydns-1.0.0/contrib/admin.php /var/www

Then edit /var/www/admin.php and configure the variables in the first part of that script, e.g. like this:

/*****************************************************************************
CONFIGURABLE OPTIONS
*****************************************************************************/

/*
** Set the following four variables to the hostname of your SQL server, the
** username and password used to access that server, and the name of the
** database where your MyDNS data resides.
*/
$dbhost = "localhost";
$dbuser = "mydns";
$dbpass = "mydns_password";
$dbname = "mydns";


/*
** This script uses MySQL by default. To use PostgreSQL instead, set
** '$use_pgsql' to '1'.
*/
$use_pgsql = 0;


/*
** The following two variables tell this script the name of your SOA
** table and the name of your RR table.
*/
$soa_table_name = "soa";
$rr_table_name = "rr";


/*
** The following two values configure the number of records shown per page
** in the zone browser and the resource record editor, respectively.
*/
$zone_group_size = 25;
$rr_group_size = 20;


/*
** This script can automatically update the serial number for a zone
** whenever a client modifies any record in that zone.
** Setting '$auto_update_serial' to '1' will enable this option.
*/
$auto_update_serial = 1;


/*
** This script can automatically update PTR records when you modify,
** add, or delete A records. To enable this functionality, set
** '$auto_update_ptr' to '1'. If you enable this, be sure to fill in
** the values for '$default_ns' and '$default_mbox', below, so that
** new SOA records will have the correct information.
*/
$auto_update_ptr = 1;


/*
** If this option is nonzero, this script will not complain if the
** TTL for a record is set below the zone minimum.
**
** Note that if $ttl_min below is nonzero, that value will still be
** checked.
*/
$ignore_minimum_ttl = 1;


/*
** The following values are used by this script to enforce minimum values
** for SOA and RR records. The script will prevent clients from entering
** values lower than these numbers.
*/
$ttl_min = 300;
$refresh_min = 300;
$retry_min = 300;
$expire_min = 86400;


/*
** The following two variables specify the default nameserver for new
** SOA records, and the default administrator mailbox for new SOA records.
** These will be filled in automatically whenever a new zone is created.
*/
$default_ns = "ns1.example.com.";
$default_mbox = "admin.example.com.";


/*
** The following array specifies default records for new SOA records.
** These get inserted automatically whenever a SOA is inserted.
** The format of each record is (name, type, aux, data).
*/
$default_records = array(
array("", "NS", 0, "ns1.example.com."),
/* array("", "MX", 10, "mail.example.com.") */
);


/*
** The following five values will be used as default values whenever new
** zones are created.
*/
$default_ttl = 86400;
$default_refresh = 28800;
$default_retry = 7200;
$default_expire = 604800;
$default_minimum_ttl = 86400;


/*
** The remainder of these variables enable cosmetic changes.
*/
$fontsize = 12; /* Default font size (pixels) */

$font_color = "#663300"; /* Font color */

$page_bgcolor = "white"; /* Page background color */
$help_bgcolor = "#FFFFCC"; /* Main screen help box background color */
$soa_bgcolor = "#FFFF99"; /* SOA editor background color */

$list_bgcolor_1 = "#FFFFCC"; /* List items #1 background */
$list_bgcolor_2 = "#FFFFAA"; /* List items #2 background */

$query_bgcolor = "#FFFFCC"; /* Search query input background color */
$query_fgcolor = "black"; /* Search query input font color */

$input_bgcolor = "white"; /* Text input box background color */
$input_fgcolor = "black"; /* Text input box font color */

/**** End of configurable options *******************************************/

Take care that you fill in the correct database details. In addition to that I set $auto_update_serial and $auto_update_ptr to 1 and specify values in $default_ns and $default_mbox so that serials are incremented automatically in case of changes and PTR records are also created automatically. But of course, this is up to you if you wish that behaviour.

You can now access the web interface under http://ns1.example.com/admin.php.

2.3 Install MyDNSConfig

MyDNSConfig is an interface written by me using PHP. I found that the original MyDNS web interface is hard to handle for newbies because it does not have any field descriptions (it is easy to manage if you come from the Bind world though because of the design of the interface which resembles Bind's zone files).

You can download MyDNSConfig from http://www.mydnsconfig.org.

Now lets assume you have downloaded mydnsconfig-<version>.tar.gz to /tmp. Then you install it like this:

cd /tmp
tar xvfz mydnsconfig-<version>.tar.gz
cd mydnsconfig
cp -fr * /var/www

Then you have to adjust /var/www/lib/config.inc.php. Mine looks like this:

<?php

ini_set('register_globals',0);

$conf["app_title"] = "MyDNSConfig";
$conf["app_version"] = "1.0.0";
$conf["rootpath"] = "/var/www";

$conf["fs_div"] = "/"; // File system divider, \\ on windows and / on linux and unix
$conf["classpath"] = $conf["rootpath"].$conf["fs_div"]."lib".$conf["fs_div"]."classes";
$conf["temppath"] = $conf["rootpath"].$conf["fs_div"]."temp";

/*
Database Settings
*/

$conf["db_type"] = 'mysql';
$conf["db_host"] = 'localhost';
$conf["db_database"] = 'mydns';
$conf["db_user"] = 'mydns';
$conf["db_password"] = 'mydns_password';

/*
External programs
*/

//$conf["programs"]["convert"] = "/usr/bin/convert";
//$conf["programs"]["wput"] = $conf["rootpath"]."\\tools\\wput\\wput.exe";

/*
Themes
*/

$conf["theme"] = 'default';
$conf["html_content_encoding"] = 'text/html; charset=iso-8859-1';
$conf["logo"] = 'themes/default/images/mydnsconfig_logo.gif';

/*
Default Language
*/

$conf["language"] = 'en';

/*
Auto Load Modules
*/

$conf["start_db"] = true;
$conf["start_session"] = true;

/*
DNS Settings
*/

$conf["auto_create_ptr"] = 1; // Automatically create PTR records?
$conf["default_ns"] = 'ns1.example.com.'; // must be set if $conf['auto_create_ptr'] is 1. Don't forget the trailing dot!
$conf["default_mbox"] = 'admin.example.com.'; // Admin email address. Must be set if $conf['auto_create_ptr'] is 1. Replace "@" with ".". Don't forget the trailing dot!
$conf["default_ttl"] = 86400;
$conf["default_refresh"] = 28800;
$conf["default_retry"] = 7200;
$conf["default_expire"] = 604800;
$conf["default_minimum_ttl"] = 86400;

?>

Make sure you fill in the correct database details! If you want MyDNSConfig to automatically create reverse DNS records (PTR records) when you create a new DNS records, then set $conf['auto_create_ptr'] to 1 and specify a default name server in $conf['default_ns'] (do not forget the dot at the end!) and an admin email address in $conf['default_mbox'] (also with a dot at the end, and the @ sign must be replaced by a dot!).

Next we have to change the rr and soa table in the mydns database and create a new table needed by MyDNSConfig:

mysql -u root -p
Enter password:

Use mydns;

ALTER TABLE `rr` ADD `sys_userid` INT NOT NULL,
ADD `sys_groupid` INT NOT NULL AFTER `sys_userid`,
ADD `sys_perm_user` VARCHAR( 5 ) NOT NULL AFTER `sys_groupid`,
ADD `sys_perm_group` VARCHAR( 5 ) NOT NULL AFTER `sys_perm_user`,
ADD `sys_perm_other` VARCHAR( 5 ) NOT NULL AFTER `sys_perm_group`;

ALTER TABLE `soa` ADD `sys_userid` INT NOT NULL,
ADD `sys_groupid` INT NOT NULL AFTER `sys_userid`,
ADD `sys_perm_user` VARCHAR( 5 ) NOT NULL AFTER `sys_groupid`,
ADD `sys_perm_group` VARCHAR( 5 ) NOT NULL AFTER `sys_perm_user`,
ADD `sys_perm_other` VARCHAR( 5 ) NOT NULL AFTER `sys_perm_group`;

CREATE TABLE `sys_user` (
`userid` int(11) NOT NULL auto_increment,
`sys_userid` int(11) NOT NULL default '0',
`sys_groupid` int(11) NOT NULL default '0',
`sys_perm_user` varchar(5) NOT NULL default '',
`sys_perm_group` varchar(5) NOT NULL default '',
`sys_perm_other` varchar(5) NOT NULL default '',
`username` varchar(100) NOT NULL default '',
`passwort` varchar(100) NOT NULL default '',
`modules` varchar(255) NOT NULL default '',
`startmodule` varchar(255) NOT NULL default '',
`app_theme` varchar(100) NOT NULL default 'default',
`typ` varchar(20) NOT NULL default 'user',
`active` tinyint(4) NOT NULL default '1',
`name` varchar(100) NOT NULL default '',
`vorname` varchar(100) NOT NULL default '',
`unternehmen` varchar(100) NOT NULL default '',
`strasse` varchar(100) NOT NULL default '',
`ort` varchar(100) NOT NULL default '',
`plz` varchar(10) NOT NULL default '',
`land` varchar(50) NOT NULL default '',
`email` varchar(100) NOT NULL default '',
`url` varchar(255) NOT NULL default '',
`telefon` varchar(100) NOT NULL default '',
`fax` varchar(100) NOT NULL default '',
`language` varchar(10) NOT NULL default 'de',
`groups` varchar(255) NOT NULL default '',
`default_group` int(11) NOT NULL default '0',
PRIMARY KEY (`userid`)
) TYPE=MyISAM AUTO_INCREMENT=2 ;

INSERT INTO `sys_user` (`userid`, `sys_userid`, `sys_groupid`, `sys_perm_user`, `sys_perm_group`, `sys_perm_other`, `username`, `passwort`, `modules`, `startmodule`, `app_theme`, `typ`, `active`, `name`, `vorname`, `unternehmen`, `strasse`, `ort`, `plz`, `land`, `email`, `url`, `telefon`, `fax`, `language`, `groups`, `default_group`) VALUES (1, 1, 0, 'riud', 'riud', '', 'admin', '21232f297a57a5a743894a0e4a801fc3', 'admin,designer,resellers,sites,dns', 'dns', 'default', 'admin', 1, '', 'Administrator', '', '', '', '', '', '', '', '', '', 'en', '1,2', 1);

quit;

Now you can access MyDNSConfig under http://ns1.example.com. The default login username is admin, the password is also admin. Please change the password after your first login under System -> Edit user.

2.4 Use dig To Test Your Records

After you have created DNS records using one of the three web interfaces I have described here, you can test your records using dig. Lets assume you have created the zone test.com. (with a dot at the end!) with the A record www. When you run

dig @localhost www.test.com

the output should look like this:

:~# dig @localhost www.test.com

; <> DiG 9.2.4 <> @localhost www.test.com
;; global options: printcmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 12658
;; flags: qr aa rd; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0

;; QUESTION SECTION:
;www.test.com. IN A

;; ANSWER SECTION:
www.test.com. 86400 IN A 1.2.3.4

;; Query time: 20 msec
;; SERVER: 1.2.3.4#53(localhost)
;; WHEN: Fri Dec 16 14:14:19 2005
;; MSG SIZE rcvd: 45

If you have enabled automatic creation of PTR records in the original MyDNS web interface or in MyDNSConfig, then you can also check the reverse DNS record. If www.test.com points to 1.2.3.4, then

dig @localhost -x 1.2.3.4

should show something like this:

~# dig @localhost -x 1.2.3.4

; <> DiG 9.2.4 <> @localhost -x 1.2.3.4
;; global options: printcmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 46572
;; flags: qr aa rd; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0

;; QUESTION SECTION:
;4.3.2.1.in-addr.arpa. IN PTR

;; ANSWER SECTION:
4.3.2.1.in-addr.arpa. 86400 IN PTR www.test.com.

;; Query time: 15 msec
;; SERVER: 1.2.3.4#53(localhost)
;; WHEN: Fri Dec 16 14:21:05 2005
;; MSG SIZE rcvd: 69

Share this page:

9 Comment(s)

Add comment

Comments

From: Anonymous at: 2006-04-15 22:32:07

Article states:

MyDNS simply reads the records from the database, an

t does not have to be restarted/reloaded

when DNS records change or zones are created/edited/deleted! This is a major advantage.

Only old BIND deployments would run this way. BIND has supported dynamic updates for quite some time. Mine never goes down (well practically speaking). All of our changes to the BIND DATABASE are made dynamically.

I emphasize database, because BIND is a database... whether you want to look at that way or not. I'm not against a DNS sitting on top of a database of some other kind, but I certainly don't like tools where the data is replicated out of a sql database and into BIND... just speaking out loud. Again, serving up out of a sql database is fine... just want to point out that BIND has/is a database and you don't have to restart it to make record changes or additions (with a few exceptions.. but not 99% of what would be changed normally).

From: Azuretek at: 2008-10-10 16:42:40

Just wanted to clarify, you do have to reload the bind configuration for record changes to take effect. The benefit of running MyDNS is that you can replicate changes and backup your data the same way you would do it for any other database driven application.

Reloading bind is usually accomplished by using "rndc" which is kind of like an API connector that can be used to control bind. Issuing the command "rndc reload" will apply your record updates.

From: at: 2007-09-12 10:09:07

The occurs from an incompatability with PHP5. Easily resolved with either:

vi +2475 /var/www/admin.php *hit enter

*this will open admin.php at line 2475, now you need to edit each instance of $this to $_this

between line 2475 and 2485 

if you arn't familiar with vi, you may find it easier to use nano (please note that ^ represents the CTRL key on your keyboard, I am using it here as it is what you will see in the editor)

nano /var/www/admin.php *hit enter

^\ *hit enter

Search (to replace): $this *hit enter

Replace with: $_this *hit enter

Replace this instance?: A *hit enter

^x *hit enter 

Save modified buffer (ANSWERING "No" WILL DESTROY CHANGES) ?  Y *hit enter

File Name to Write: /var/www/admin.php *hit enter 

That's it, in the end that section should look like the following:


/**************************************************************************************************
   RR_TYPE_OPTIONS
   Returns a list of resource record types.
**************************************************************************************************/
function _rr_type_option($type, $_this) {
    return "<OPTION" . (!strcasecmp($type, $_this) ? " selected" : "") . ">$_this";
}
function rr_type_options($type)
{
   global $db_valid_types;

   reset($db_valid_types);
   $rv = '';
   foreach ($db_valid_types as $_this)
      $rv .= _rr_type_option($type, $_this);
   return $rv;
}
/*--- rr_type_options() -------------------------------------------------------------------------*/

 

From: Anonymous at: 2008-11-09 22:20:09

I would love to see how this could be used in conjuction with an existing server setup so that it would be a secondary only to what is already being used on that server. 

For example I have a VPS that I rent and I would like to be able to use MyDNS as a secondary resource so that current setup of LXAdmin would not be affected but I could still use this for certain domains or subdomains that I would like to be able to work as my own dynamic dns service on my own server.

From: Anonymous at: 2009-02-01 15:57:30

It goes to show how bad BIND's config file management really is--that--someone would write, from scratch, a DNS server using mysql to manage the records. Amazing.

From: sysAdmin at: 2010-07-20 19:33:04

I've Found a great DNS scanner that can locate any DNS server at your network (multi-subnet) it can also test if the DNS is answering anyones requests or not.
you can get it here: http://www.softpedia.com/get/Internet/Other-Internet-Related/DNS-Locator.shtml

From: at: 2008-01-03 14:21:28

If you have tried to wget from http://www.servershak.com/dns/dnsctl, you have not the right file. Mr Falko have posted the content here: /usr/local/sbin/dnsctl

If you are on linux, and are stumped, as I am, at "errno" error when compiling dnscache items, try read this: installing-dns-cache-with-djbdns

From: jamie at: 2008-12-04 20:27:11

Thanks to debian for hiding 'sarge' in favour of v4.1 Also the packages required to install sarge are no longer available from any of the mirrors. So... either download 13 CD's OR don't bother.

 I know what my favoured option is.

 Frankly I don't see why Bind for windows doesn't support using mysql by default. It's pathetic. Just like apache which also wants constant restarts to recognise new hosts...

From: Anonymous at: 2009-10-20 19:53:01

MyDNS 1.1.0 appears to support recursive lookups through the support of a second DNS server that can do recursive lookups.    This was a good thing to find as I was moving from BIND9 to MyDNS.

The /etc/mydns.conf has a variable [recursive] where I was able to enter the IP address.  This gave me what I needed to allow MyDNS to be a authoritative server while also providing a path for resolution for those who used the server as a name server on remote systems.