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

Want to support HowtoForge? Become a subscriber!
 
Submitted by falko (Contact Author) (Forums) on Mon, 2006-01-02 15:53. ::

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


Please do not use the comment function to ask for help! If you need help, please use our forum.
Comments will be published after administrator approval.