DNS-Konfiguration per Datenbank mit bind-dlz

Seit BIND9.4 ist der DLZ-Patch mit enthalten. Um ihn unter Debian nutzen zu können muss in der Datei debian/rules das Einkompilieren von PostgreSQL und/oder MySQL aktiviert werden:

--with-dlz-postgres=yes \
--with-dlz-mysql=yes \

Dann kann man in der BIND-Konfiguration die dynamische Zone aktivieren:

dlz "Mysql zone" {
   database "mysql
   {host=localhost dbname=dns_data user=dns_data pass=password 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%'}
   {}
   {select ttl, type, host, mx_priority, data
        from dns_records where zone = '%zone%' and not (type = 'SOA' or type = 'NS')}
   {select zone from xfr_table where zone = '%zone%' and client = '%client%'}
   {}";
};

Als Testdaten kann man folgenden SQL-Dump einspielen:

/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101example.com SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE=‘NO_AUTO_VALUE_ON_ZERO’ */;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;


# Dump of table data_count
# ------------------------------------------------------------

CREATE TABLE `data_count` (
  `count` bigint(20) default ‘0’,
  `zone` char(64) default NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

LOCK TABLES `data_count` WRITE;
/*!40000 ALTER TABLE `data_count` DISABLE KEYS */;
INSERT INTO `data_count` (`count`,`zone`)
VALUES
        (0,’example.com’);

/*!40000 ALTER TABLE `data_count` ENABLE KEYS */;
UNLOCK TABLES;


# Dump of table dns_records
# ------------------------------------------------------------

CREATE TABLE `dns_records` (
  `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) default NULL,
  `retry` int(11) default NULL,
  `expire` int(11) default NULL,
  `minimum` int(11) default NULL,
  `serial` bigint(20) default NULL,
  `resp_person` varchar(64) default NULL,
  `primary_ns` varchar(64) default NULL,
  KEY `host` (`host`),
  KEY `zone` (`zone`),
  KEY `type` (`type`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

LOCK TABLES `dns_records` WRITE;
/*!40000 ALTER TABLE `dns_records` DISABLE KEYS */;
INSERT INTO `dns_records` (`zone`,`host`,`type`,`data`,`ttl`,`mx_priority`,`refresh`,`retry`,
`expire`,`minimum`,`serial`,`resp_person`,`primary_ns`)
VALUES
(‘example.com’,’@‘,’SOA’,’@‘,3600,NULL,10800,1800,604800,3600,2008082700,
  ’root.example.com.’,’ns1.example.com’),
(‘example.com’,’@‘,’A’,’192.0.2.1’,3600,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL),
(‘example.com’,’@‘,’NS’,’ns1.example.com.’,3600,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL),
(‘example.com’,’@‘,’NS’,’ns2.example.com.’,3600,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL),
(‘example.com’,’@‘,’NS’,’ns3.example.com.’,3600,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL),
(‘example.com’,’@‘,’AAAA’,’2001:0db8::1’,3600,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL),
(‘example.com’,’www’,’AAAA’,’2001:0db8::1’,3600,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL),
(‘example.com’,’www’,’A’,’192.0.2.1’,3600,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL),
(‘example.com’,’@‘,’MX’,’ns1.example.com.’,3600,10,NULL,NULL,NULL,NULL,NULL,NULL,NULL);

/*!40000 ALTER TABLE `dns_records` ENABLE KEYS */;
UNLOCK TABLES;


# Dump of table xfr_table
# ------------------------------------------------------------

CREATE TABLE `xfr_table` (
  `zone` text,
  `client` text
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

LOCK TABLES `xfr_table` WRITE;
/*!40000 ALTER TABLE `xfr_table` DISABLE KEYS */;
INSERT INTO `xfr_table` (`zone`,`client`)
VALUES
        (‘example.com’,’127.0.0.1’);

/*!40000 ALTER TABLE `xfr_table` ENABLE KEYS */;
UNLOCK TABLES;

/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;

Leave a Reply