# Bind, dlz and AXFR

## ferferhosting

Hello,

I've installed bind 9.2.5-r4 with dlz/mysql bindings, with this USE:

[ebuild   R   ] net-dns/bind-9.2.5-r4  +berkdb +bind-mysql +dlz -doc -idn +ipv6 -ldap +mysql -odbc -postgres (-selinux) +ssl -threads 0 kB

I've set up my mysql database and my named.conf:

```
mysql> select * from dns_records;

+---------+------+------+------+--------+--------------+---------------+--------+---------+-------+--------+---------+

| zone    | host | ttl  | type | mx_pri | data         | resp_person   | serial | refresh | retry | expire | minimum |

+---------+------+------+------+--------+--------------+---------------+--------+---------+-------+--------+---------+

| ffh.com | @    |   10 | soa  |        | ns1.ffh.com. | root.ffh.com. | 2      | 28000   | 2800  | 64800  | 10      |

| ffh.com | @    |   10 | ns   |        | ns1.ffh.com. |               |        |         |       |        |         |

| ffh.com | @    |   10 | ns   |        | ns2.ffh.com. |               |        |         |       |        |         |

| ffh.com | @    |   10 | mx   | 10     | ffh.com.     |               |        |         |       |        |         |

| ffh.com | mail |   10 | mx   | 10     | ffh.com.     |               |        |         |       |        |         |

| ffh.com | @    |   10 | a    |        | 6.6.2.1      |               |        |         |       |        |         |

| ffh.com | ns1  |   10 | a    |        | 6.6.2.1      |               |        |         |       |        |         |

| ffh.com | ns2  |   10 | a    |        | 6.6.2.1      |               |        |         |       |        |         |

| ffh.com | mail |   10 | a    |        | 6.6.2.1      |               |        |         |       |        |         |

| ffh.com | www  |   10 | a    |        | 6.6.2.1      |               |        |         |       |        |         |

+---------+------+------+------+--------+--------------+---------------+--------+---------+-------+--------+---------+
```

```
/etc/bind/named.conf:

options {

        directory "/var/bind";

        // uncomment the following lines to turn on DNS forwarding,

        // and change the forwarding ip address(es) :

        //forward first;

        //forwarders {

        //      123.123.123.123;

        //      123.123.123.123;

        //};

        listen-on-v6 { none; };

        listen-on { any; };

        // to allow only specific hosts to use the DNS server:

        //allow-query {

        //      127.0.0.1;

        //};

        // if you have problems and are behind a firewall:

        //query-source address * port 53;

        pid-file "/var/run/named/named.pid";

        allow-recursion { localhost; };

        allow-transfer { any; };

};

logging {

        channel named_log {

                file "/var/log/named/named.log" versions 3 size 2m;

                severity info;

        };

        category default {

                named_log;

        };

};

dlz "Mysql zone" {

   database "mysql

   {host=localhost dbname=somedb ssl=false port=3306 user=someuser pass=somepass }

   {select zone from dns_records where zone = '%zone%' limit 1}

   {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 as mydata from dns_records where zone = '%zone%' and host = '%record%'}";

};

zone "." IN {

        type hint;

        file "named.ca";

};

zone "localhost" IN {

        type master;

        file "pri/localhost.zone";

        allow-update { none; };

        notify no;

};

zone "127.in-addr.arpa" IN {

        type master;

        file "pri/127.zone";

        allow-update { none; };

        notify no;

};

```

This works well, and I can dig @localhost whatever and it works. But I can't make any transfer (I know, I have not written all the queries needed).

So, if I change named.conf in this way:

```

dlz "Mysql zone" {

   database "mysql

   {host=localhost dbname=somedb ssl=false port=3306 user=someuser pass=somepass }

   {select zone from dns_records where zone = '%zone%' limit 1}

   {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 as mydata from dns_records where zone = '%zone%' and host = '%record%'}

   {}

   {select  ttl, type, host, mx_priority, case when lower(type)='txt' then concat('\"', data, '\"') else data end as mydata, resp_person, serial, refresh, retry, expire, minimum from dns_records where zone = '%zone%'}

   {select zone from xfr_table where zone = '%zone%' and client = '%client%' limit 1}

   {update data_count set count = count + 1 where zone ='%zone%'}";

};

```

And then I try to do a dig @localhost ffh.com AXFR after /usr/sbin/named -u named -n 1 -g -d 1, I get this:

```

...

Jun 08 17:28:40.676 Loading 'Mysql zone' using driver mysql

...

Jun 08 17:29:20.211

Query String: select zone from dns_records where zone = ffh.com' limit 1

Jun 08 17:29:20.216

Query String: update data_count set count = count + 1 where zone ='ffh.com'

Jun 08 17:29:20.219

Query String: select zone from xfr_table where zone = 'ffh.com' and client = '127.0.0.1' limit 1

Jun 08 17:29:20.222

Query String: 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 as mydata from dns_records where zone = 'ffh.com' and host = '@'

Jun 08 17:29:20.278

Query String: select  ttl, type, host, mx_priority, case when lower(type)='txt' then concat('"', data, '"') else data end as mydata, resp_person, serial, refresh, retry, expire, minimum from dns_records where zone = 'ffh.com'

Jun 08 17:29:20.284

Query String: 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 as mydata from dns_records where zone = 'ffh.com' and host = '@'

Jun 08 17:29:20.289 db.c:391: REQUIRE(source != ((void *)0)) failed

Jun 08 17:29:20.289 exiting (due to assertion failure)

Aborted

~#

```

The daemon stops, and I got ";; communications error to 127.0.0.1#53: end of file" in the dig session.

Does anyone know what can be happening? I really don't need AXFR (I've read about it in DLZ Homepage) but, in my config, I only admit transfers from localhost and I find useful to use it via dig to retrieve and review all the info about a domain.

Thank you!

----------

## sjap

Hey...

Do you have a guide to bind @ mysql??

----------

## ferferhosting

This is part of the guide I made for myself. I assume you have installed mysql and it is working.

 *Quote:*   

> 
> 
> # in /etc/make.conf make sure you have USE="... bind-mysql mysql dlz ..."
> 
> # emerge bind & bind utils
> ...

 

SQLs I use for adding domain mydomain.com to the database:

 *Quote:*   

> 
> 
> # SOA
> 
> INSERT INTO dns_records
> ...

 

If you run into troubles, you should tail /var/log/syslog and tail /var/log/named/named.log .

Hope this helps.

----------

## sjap

Thx  :Smile: 

I will try it now  :Smile: 

but is it working for you?

----------

## ferferhosting

Yes. Transfer does not work, but everything else does.

----------

## sjap

okay, nice  :Very Happy: 

----------

## sjap

hmm...

Named failed to start :S

My log fil:

Jul 15 19:46:15 [named] Loading 'sjap.com' using driver mysql

Jul 15 19:46:15 [named] mysql driver failed to create database connection after 4 attempts

Jul 15 19:46:15 [named] SDLZ driver failed to load.

Jul 15 19:46:15 [named] DLZ driver failed to load.

What can it be?

----------

## sjap

My mysqlserver works, and bind is compilet with dlz, mysql mysql-bind

----------

## ferferhosting

 *Quote:*   

> Jul 15 19:46:15 [named] mysql driver failed to create database connection after 4 attempts 

 

You should check in /etc/bind/named.conf 

```
{host=localhost dbname=named ssl=false port=3306 user=named pass=named }
```

You should replace those params with correct ones.

Try doing this at shell (be careful with spaces)

```
mysql -h localhost -u named -pnamed named
```

where it means "-h host -u user -ppassword databasename"

If that works and let you connect, DLZ should be able to connect too.

BTW, your mysql daemon should be started BEFORE bind starts. I had to tweak my /etc/init.d scripts to have this done in boot time. You can try

```
/etc/init.d/named stop

/etc/init.d/mysqld stop

/etc/init.d/mysqld start

/etc/init.d/named start
```

If they start in that order, everything should work.

----------

## sjap

Thx... This working fine now.. 

I use this in my named.conf 

and I switch from "host=localhost" to "host=127.0.0.1"

dlz "Mysql zone" {

   database "mysql

   {host=127.0.0.1 dbname=named user=xxxx pass=xxxx}

   {select zone from dns_records where zone = '%zone%'}

   {select ttl, type, mx_priority, case when lower(type)='txt' then concat('\"', data, '\"')

        else data end from dns_records where zone = '%zone%' and host = '%record%'

        and not (type = 'SOA' or type = 'NS')}

   {select ttl, type, mx_priority, data, resp_person, serial, refresh, retry, expire, minimum

        from dns_records where zone = '%zone%' and (type = 'SOA' or type='NS')}

   {select ttl, type, host, mx_priority, data, resp_person, serial, refresh, retry, expire,

        minimum from dns_records where zone = '%zone%' and not (type = 'SOA' or type = 'NS')}

   {select zone from xfr_table where zone = '%zone%' and client = '%client%'}

   {update data_count set count = count + 1 where zone ='%zone%'}";

};

And my reverse zone is in mysql to  :Smile: 

That's very nice  :Very Happy: 

----------

