Contact Me

Evocatio - Solutions Technologiques

514.667.0559

Installer un serveur DNS(bind) avec un backend MySQL sous Ubuntu 10.04

Posted on Thursday, 10th June, 2010

But

Installation d’un serveur DNS(bind9) avec un backend MySQL sous Ubuntu 10.04

Pré-requis

  1. Préparer l’environement en exécutant :
    mkdir -p /usr/local/src/bind9
    cd /usr/local/src/bind9
  2. Installer les pacquets nessécaires :
    apt-get update -y
    apt-get install -y build-essential mysql-server fakeroot bison libmysqlclient15-dev \
     libkrb5-dev libkrb5-dev libssl-dev libtool libdb-dev libldap2-dev libldap2-dev libcap2-dev \
     hardening-wrapper debhelper libxml2-dev libgeoip-dev
    apt-get source -y bind9

BIND

Préparation

  1. Récupurer le nom du répertoire (varie selon la version)
    ls -1
    Voici un exemple de résultat, le nom recherché est marqué en gras
    bind9-9.5.1.dfsg.P2 bind9_9.5.1.dfsg.P2-1.diff.gz bind9_9.5.1.dfsg.P2-1.dsc bind9_9.5.1.dfsg.P2.orig.tar.gz
  2. Entrer dans le répertoire
    cd bind9-9.5.1.dfsg.P2
  3. Éditer le fichier des règles de compilation
    vi debian/rules
    Et changer la ligne –with-dlz-mysql=no par –with-dlz-mysql=yes ou vous pouvez exécuter la commande suivante dans vi :
    :%s/dlz-mysql=no/dlz-mysql=yes/g
    Enregistrer le fichier et quitter
    :wq

Compilation

Pour compiler l’application exécuter la commande suivante :

dpkg-buildpackage -rfakeroot -b
Si dpkg-buildpackage vous spécifie qu’il manque des dépendances (unmet dependencies) Installer les dépendances avec la commande apt-get install et réessailler.

Installation

  1. Reculer d’un répertoire :
    cd ..
    ls -l
    bind9-9.5.1.dfsg.P2 bind9_9.5.1.dfsg.P2-1_amd64.changes bind9_9.5.1.dfsg.P2-1_amd64.deb bind9_9.5.1.dfsg.P2-1.diff.gz bind9_9.5.1.dfsg.P2-1.dsc bind9_9.5.1.dfsg.P2.orig.tar.gz bind9-doc_9.5.1.dfsg.P2-1_all.deb bind9-host_9.5.1.dfsg.P2-1_amd64.deb bind9utils_9.5.1.dfsg.P2-1_amd64.deb dnsutils_9.5.1.dfsg.P2-1_amd64.de libbind9-40_9.5.1.dfsg.P2-1_amd64.deb libbind-dev_9.5.1.dfsg.P2-1_amd64.deb libdns45_9.5.1.dfsg.P2-1_amd64.deb libisc45_9.5.1.dfsg.P2-1_amd64.deb libisccc40_9.5.1.dfsg.P2-1_amd64.deb libisccfg40_9.5.1.dfsg.P2-1_amd64.deb liblwres40_9.5.1.dfsg.P2-1_amd64.deb lwresd_9.5.1.dfsg.P2-1_amd64.deb
  2. Installer les pacquets sur votre système.
    dpkg -i *.deb

Configuration

  1. Forcer bind a être exécuter en un seul thread. Éditier le fichier /etc/default/bind9/etc/default/bind9
    1. run resolvconf? RESOLVCONF=yes
    2. startup options for the server OPTIONS=”-u bind -n 1
      Bind semble avoir un problème lorsque qu’il est exécuter en multithread. L’erreur “mysql driver unable to return result set for findzone query” apparait dans les fichier de log et bind fini par arrêter.

  2. Voici un exemple pour le fichier /etc/bind/named.conf.localcat /etc/bind/named.conf.local

    dlz "Mysql zone" {
       database "mysql
       {host=localhost dbname=Nom_de_la_Base_de_Donnee user=Nom_d_utilisateur pass=Mot_de_passe ssl=false}
       {select zone from dns_records where zone = '$zone$'}
       {select ttl, type, mx_priority, case when lower(type)='txt' then concat('\"', data, '\"')
            when lower(type) = 'soa' then concat_ws(' ', data, resp_person, serial, refresh, retry, expire, minimum)
            else data end from dns_records where zone = '$zone$' and host = '$record$'}";
    };

MySQL

Creation d’un utilisateur et d’une base de données

CREATE USER 'Nom_d_Utilisateur'@'localhost' IDENTIFIED BY  '***';
GRANT USAGE ON * . * TO  'Nom_d_Utilisateur'@'localhost' IDENTIFIED BY  '***' WITH MAX_QUERIES_PER_HOUR 0 MAX_CONNECTIONS_PER_HOUR 0 MAX_UPDATES_PER_HOUR 0 MAX_USER_CONNECTIONS 0 ;
 
CREATE DATABASE IF NOT EXISTS  `Nom_de_la_base_de_donnée` ;
 
GRANT ALL PRIVILEGES ON  `Nom_de_la_base_de_donnée`.* TO  'Nom_d_Utilisateur'@'localhost';

Création du schéma

Exécuter sur le serveur SQL :

CREATE TABLE IF NOT EXISTS `dns_records` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `zone` varchar(64) DEFAULT NULL,
  `host` varchar(64) DEFAULT NULL,
  `type` varchar(8) DEFAULT NULL,
  `data` varchar(64) DEFAULT NULL,
  `ttl` int(11) NOT NULL DEFAULT '3600',
  `mx_priority` int(11) DEFAULT NULL,
  `refresh` int(11) NOT NULL DEFAULT '3600',
  `retry` int(11) NOT NULL DEFAULT '3600',
  `expire` int(11) NOT NULL DEFAULT '86400',
  `minimum` int(11) NOT NULL DEFAULT '3600',
  `serial` bigint(20) NOT NULL DEFAULT '2008082700',
  `resp_person` varchar(64) NOT NULL DEFAULT 'resp.person.email',
  `primary_ns` varchar(64) NOT NULL DEFAULT 'ns1.yourdns.here',
  `data_count` int(11) NOT NULL DEFAULT '0',
  PRIMARY KEY (`id`),
  KEY `host` (`host`),
  KEY `zone` (`zone`),
  KEY `type` (`type`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1;

Donnée d’exemple

INSERT INTO `dns_records` (`id`, `zone`, `host`, `type`, `data`, `ttl`, `mx_priority`, `refresh`, `retry`, `expire`, `minimum`, `serial`, `resp_person`, `primary_ns`, `data_count`) VALUES
(1, 'test.cat.io', 'www', 'A', '1.2.3.4', 3600, NULL, 3600, 3600, 86400, 3600, 2008082700, 'resp.person.email', 'ns1.yourdns.here', 0),
(2, 'test.cat.io', 'patate', 'A', '245.241.2.1', 3600, NULL, 3600, 3600, 86400, 3600, 2008082700, 'resp.person.email', 'ns1.yourdns.here', 0),
(3, 'test.cat.io', '@', 'A', '1.2.3.4', 3600, NULL, 3600, 3600, 86400, 3600, 2008082700, 'resp.person.email', 'ns1.yourdns.here', 0),
(4, 'test.cat.io', 'www2', 'CNAME', 'www.domain.com.', 3600, NULL, 3600, 3600, 86400, 3600, 2008082700, 'resp.person.email', 'ns1.yourdns.here', 0),
(5, 'test.cat.io', '@', 'MX', 'domain.com.', 3600, 0, 3600, 3600, 86400, 3600, 2008082700, 'resp.person.email', 'ns1.yourdns.here', 0);

Redémarrer et tester

reboot

References

 

 

avatar

Your name

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">

Etienne Lachance - Copyright © 2009 - Dragon Technologie - Tout droits réservés