stop DNS replication in a ISPConfig cluster


The following post refers to http://www.howtoforge.com/forums/showthread.php?t=62702

When using several servers for web and / or mail, all must each be recorded in the DNS. But if one server fails, the DNS entries have to be adjusted accordingly; a round-robin DNS solution leads to timeouts, too. If only the local IP is registered on each server in the DNS, only requests for its own IP could be answered. It´s important that all NS records are included.

To stop the DNS replication in a ISPConfig cluster, change in server/plugins-available/bind_plugin.inc.php line 104 from

$records = $app->db->queryAllRecords("SELECT * FROM dns_rr WHERE zone = ".$zone['id']." AND active = 'Y'");

to

$records = $app->db->queryAllRecords("SELECT * FROM dns_rr WHERE zone=".$zone['id']." AND active = 'Y' AND (data NOT IN (SELECT ip_address FROM server_ip WHERE server_ip.server_id<>".$conf["server_id"].") OR name REGEXP '^ns')");

The SQL call looks at first glance perhaps a little confusing, but can be easily disassembled:

SELECT * FROM dns_rr WHERE zone=".$zone['id']." AND active = 'Y'

Search all active DNS entries for the zone.

AND (
data NOT IN
(
SELECT ip_address FROM server_ip WHERE server_ip.server_id<>".$conf["server_id"]."
)

By data NOT IN the IP addresses of other servers will be filtered. The addresses are in the table server_ip and are linked to respective server ID. So we just need a second SELECT in which all IP addresses are selected that do not belong to the current server (on that the script is being executed).
You can write the IP addresses of other servers directly in the script, but with more than two servers it is awkward; especially since the source code on each server is different then.

OR name REGEXP '^ns'
)

Exempted from filtering are all entries that begin with ns . Otherwise, only the DNS would show up on the current server in the zone file at best.

The regex can be expanded. Who wants all the entries with mx to start in the DNS have, instead takes

OR name REGEXP '^ns|^mx'

.

Leave a comment

Your email address will not be published. Required fields are marked *