MyDNS with MyDNSConfig Control Panel and DNSMasq on Ubuntu 6.10

Want to support HowtoForge? Become a subscriber!
 
Submitted by till (Contact Author) (Forums) on Thu, 2007-03-08 17:20. :: MyDNS | Ubuntu | Control Panels | DNS

MyDNS with MyDNSConfig Control Panel and DNSMasq on Ubuntu 6.10

Version 1.0
Author: Till Brehm <t.brehm [at] projektfarm [dot] com>
Last edited 03/06/2007

In this tutorial I will describe how to install and configure MyDNS and MyDNSConfig. MyDNS is a DNS server that uses a MySQL database as backend instead of configuration files like, for example, Bind or djbdns. The advantage is that MyDNS simply reads the records from the database, and it does not have to be restarted/reloaded when DNS records change or zones are created/edited/deleted. A secondary nameserver can be easily set up by installing a second instance of MyDNS that accesses the same database or, to be more redundant, uses the MySQL master / slave replication features to replicate the data to the secondary nameserver.

MyDNSConfig is an easy to use web-based interface to MyDNS. MyDNSConfig can create all types of DNS records that are available in MyDNS and adds features like user management and access privileges.

This setup uses Ubuntu 6.10, but it should work with Debain Etch, too.

 

Installing The Prerequisites

MyDNSConfig is a web-based interface to MyDNS written in PHP. This requires a webserver with PHP enabled and the MySQL database server. If you have already Apache, PHP and MySQL installed, you may skip this step.

Installing MySQL and Apache webserver:

apt-get install libdbd-mysql-perl libdbi-perl libmysqlclient15off libnet-daemon-perl libplrpc-perl mysql-client mysql-client-5.0 mysql-server mysql-common apache2 phpmyadmin libapache2-mod-php5

Set the MySQL root password:

mysqladmin -u root password yourrootsqlpassword

Replace yourrootsqlpassword with a password of your choice.

 

Installing MyDNSConfig

I will use the MyDNS package from the Ubuntu universe repository. Befor you go to the next steps, please make sure that the universe repository is enabled in /etc/apt/sources.list.

Log in to MySQL and create the database:

mysql -u root -p

CREATE DATABASE mydns;
GRANT SELECT, INSERT, UPDATE, DELETE ON mydns.* TO 'mydns'@'localhost' IDENTIFIED BY 'mydnspassword';
GRANT SELECT, INSERT, UPDATE, DELETE ON mydns.* TO 'mydns'@'localhost.localdomain' IDENTIFIED BY 'mydnspassword';
FLUSH PRIVILEGES;
quit;

Replace the word mydnspassword in the above commands with a password of your choice.

Download MyDNSConfig:

cd /tmp
wget http://mesh.dl.sourceforge.net/sourceforge/mydnsconfig/MyDNSConfig-1.1.0.tar.gz
tar xvfz MyDNSConfig-1.1.0.tar.gz
cd MyDNSConfig-1.1.0

Install MyDNSConfig:

mkdir /usr/share/mydnsconfig
cp -rf interface/* /usr/share/mydnsconfig/
ln -s /usr/share/mydnsconfig/web/ /var/www/mydnsconfig

Install the MyDNSConfig SQL Database:

mysql -u root -p mydns < install/mydnsconfig.sql

The command above asks for a password, please enter the password of the MySQL root user.

Edit the MyDNSConfig configuration:

vi /usr/share/mydnsconfig/lib/config.inc.php

The file should look like this:

<?php
/*
Copyright (c) 2005, Till Brehm, Falko Timme, projektfarm Gmbh
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
    * Redistributions of source code must retain the above copyright notice,
      this list of conditions and the following disclaimer.
    * Redistributions in binary form must reproduce the above copyright notice,
      this list of conditions and the following disclaimer in the documentation
      and/or other materials provided with the distribution.
    * Neither the name of ISPConfig nor the names of its contributors
      may be used to endorse or promote products derived from this software without
      specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
ini_set('register_globals',0);
$conf["app_title"] = "MyDNSConfig";
$conf["app_version"] = "1.1.0";

$conf["rootpath"]            = "/usr/share/mydnsconfig";
$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"]        = 'mydnspassword';

/*
        External programs
*/
$conf["programs"]["wput"]    = $conf["rootpath"]."/tools/wput/wput";

/*
        Themes
*/
$conf["theme"]            = 'grey';
$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;
?>

Afterwards, remove the MyDNSConfig installer from the /tmp directoy:

cd /tmp
rm -rf MyDNSConfig-1.1.0/
rm -f MyDNSConfig-1.1.0.tar.gz

 

Installing MyDNS

Now install the MyDNS package from Ubuntu. As we created a database named mydns already which contains all the tables needed for MyDNS, we can choose to not create the database in the following setup.

apt-get install mydns-mysql

-> localhost
-> mydns
-> no
-> mydns
-> mydnspassword

Modify the MyDNS configuration file so that MyDNS will listen also on TCP and allow zone transfers:

vi /etc/mydns.conf

allow-tcp = yes
allow-axfr = yes

The basic installation of MyDNS and MyDNSConfig is now finished. To log in to the MyDNSConfig interface, open a web browser and enter enter the following URL:

http://<your_ip_address>/mydnsconfig/

Replace <your_ip_address> with the IP address of your server.

The default username and password of MyDNSConfig is:

Username: admin
Password: admin

Don't forget to change the password after login under System > Users.

 

Installing DNSMasq

MyDNS does not contain a DNS resolver that is able to resolve DNS records that MyDNS is not athoritive for. In the next step I will install and configure the DNS resolver and cache DNSMasq to act as a local DNS resolver and configure MyDNS to use DNSMasq to resolve external domains. If you don't want your server to resolve external domains, you can skip this part.

Create a DNS Resolver on IP 127.0.0.1:

apt-get install dnsmasq

This installs the dnsmasq Ubuntu package. Now we will have to edit the DNSMasq and MyDNS configuration files to ensure that both pacakges won't listen on the same port on all IP addresses.

vi /etc/dnsmasq.conf

listen-address=127.0.0.1
no-dhcp-interface=
bind-interfaces

Now edit the mydns.conf file to configure MyDNS to not listen on 127.0.0.1:

vi /etc/mydns.conf

no-listen = 127.0.0.1
recursive = 127.0.0.1

Then edit /etc/resolv.conf:

vi /etc/resolv.conf

and add the following line as first line so that the DNSMasq DNS-Cache is used for all local DNS queries, too:

nameserver 127.0.0.1

 

Links


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.
Submitted by chippyash (registered user) on Sun, 2008-06-01 07:59.

Great little series of tutorials - had a DNS server up and running in 1/2 an hour.  Just to help others a couple of additional pointers:

1/ Test your system using the host and/or dig command (use man host/dig for details) before your connect up to rest of network.

2/ Set your DNS entries on the LAN side of  the firewall if you are using your firewall as the DHCP server.  Leave the WAN side alone.  If you are using this in a small private network (such as at home or in a small office) it is probably sufficient to have one internal DNS server so you can point your 2 DNS entries on the DHCP server with the first at your internal DNS server and the second at your internal Gateway address (usually the firewall.)

If you do this and assuming that you are using dnsmasq, then if your  internal DNS falls over, you will still get external name resolution.

Submitted by curiogeo (registered user) on Thu, 2007-03-22 02:25.

Bravo.

This tutorial is very informative and very effective.  It is easier to understand modifying sql tables to bind records and domains.

Suggested Additions

One place where it could be improved is to add mention of the fact that mysql must be enabled for php or the mydnsconfig webpage will fail.  (I fixed mine by making the following adjustment in /etc/php5/apache2/php.ini: extension=mysql.so )

My second comment to help other newbies like myself  would be to add some kind of guide to the syntax of records (ie.  http://www.debianhelp.co.uk/dnsrecords.htm) and test procedures to ensure DNS and resolver are working properly.