DnsSql
- What is DnsSql?
DnsSql is a suite of scripts designed to facilitate keeping all Bind's zone information into a database, and to generate the zone files using the same SQL backend. One script is provided for importing all your zones into a database, and then all the modifications will be done on the database, and the respective zones exported to files.
- What are the requirements?
The scripts are written in Perl, designed to work with a MySQL backend, but that can be easily changed due to the db-independent interface of Perl. The only problem that could appear is the 'auto_increment' feature of MySQL. The zone files generated will work with Bind 9.
- How does the database structure look like?
mysql> show tables;
+-------------------+
| Tables_in_bindsql |
+-------------------+
| hosts |
| ns_mx |
| zones |
+-------------------+
The most important table is the 'zones' table, which has one entry for each zone. The fields are self explanatory:
mysql> desc zones;
+---------+------------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+---------+------------------+------+-----+---------+----------------+
| id | int(10) unsigned | | PRI | NULL | auto_increment |
| zone | varchar(255) | YES | MUL | NULL | |
| ttl | int(10) unsigned | YES | | NULL | |
| soa | varchar(255) | YES | | NULL | |
| serial | int(10) unsigned | YES | | NULL | |
| refresh | varchar(10) | YES | | NULL | |
| retry | varchar(10) | YES | | NULL | |
| expire | varchar(10) | YES | | NULL | |
| min_ttl | varchar(10) | YES | | NULL | |
+---------+------------------+------+-----+---------+----------------+
This table can be created with the following command:
CREATE TABLE `zones` (
`id` int(10) unsigned NOT NULL auto_increment,
`zone` varchar(255) default NULL,
`ttl` int(10) unsigned default NULL,
`soa` varchar(255) default NULL,
`serial` int(10) unsigned default NULL,
`refresh` varchar(10) default NULL,
`retry` varchar(10) default NULL,
`expire` varchar(10) default NULL,
`min_ttl` varchar(10) default NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `zone` (`zone`)
) TYPE=MyISAM
The 'id' in the table 'zones' will be used as the zone identifier in tables 'ns_mx' and 'hosts'. Table 'ns_mx' contains all the NS and MX type of entries:
mysql> desc ns_mx;
+---------+------------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+---------+------------------+------+-----+---------+----------------+
| id | int(10) unsigned | | PRI | NULL | auto_increment |
| zone_id | int(10) unsigned | YES | | NULL | |
| type | enum('NS','MX') | YES | | NULL | |
| mx_pri | int(10) unsigned | YES | | NULL | |
| value | varchar(255) | YES | | NULL | |
+---------+------------------+------+-----+---------+----------------+
The last table is the table 'hosts', which contains all the hosts in all the zones (of course, you can identify which hosts are part of which zone by the 'zone_id' field). Unfortunately, the 'type' field has been only designed for 'A's or 'CNAME's, but not for 'RR's (I didn't need those). Maybe somebody offers to do that (modify the parsing scripts, I mean)?
mysql> desc hosts;
+---------+-------------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+---------+-------------------+------+-----+---------+----------------+
| id | int(10) unsigned | | PRI | NULL | auto_increment |
| zone_id | int(10) unsigned | YES | | NULL | |
| host | varchar(255) | YES | | NULL | |
| type | enum('A','CNAME') | YES | | NULL | |
| value | varchar(255) | YES | | NULL | |
+---------+-------------------+------+-----+---------+----------------+
- What scripts are provided?
- A script that will parse your existing zone files, and insert the datas into the database. Basically you need this utility only the first time. Fetch it [here].
- A script which will export the existing zones from the database into the respective Bind 9 zone files.