📜 ⬆️ ⬇️

System automatically generate settings for the DNS server Bind

The service often has to create a lot of DNS zones, add or modify records in them. Manually, this is a rather painstaking and complicated process: after all, you need to keep in mind the syntax and not make mistakes in the details. For such things, the most it is to get the job done by the computer

IAdmin is a system created for the automatic generation of Bind configs on a hosting server and represents the iadmin database in the MySQL database and a script that generates configuration files based on the data from the database. To set up Bind, dns_domains, dns_records, dns_subgmail tables are used. The main script written in Perl reads data from the iadmin database and creates configuration files. Zone files are generated in the / var / cache / bind / directory. Other zone files that are not served by iadmin are also stored there. The same system creates a config for the secondary-DNS, which is transferred there. Until the script runs, all changes from the database are NOT materialized.

Data


Dns_domains table


The table consists of the following fields and is the main table for configuring the DNS server:

For example, in order to add the English-speaking iadmin.vip zone to the service, with gmail and without ftp (hosting 123.123.4.56), you need to write the following line in the table:
id
domainname
www
ftp
mail
typemail
secondaryfor
hosted_on
enable
serial
owner
215
iadmin.vip
one
0
one
gmail
Null
123.123.4.56
one
2010082001
one

')


This entry will allow you to generate a zone file of approximately the following content:
 $ TTL 86400
 iadmin.vip.  IN SOA ns0.english.com.  ns1.english.com.  (
                 2010082001;  serial
                 10800;  refresh
                 3600;  retry
                 604800;  expire
                 86400);  minimum
                 IN NS ns0.english.com.
                 IN NS ns1.english.com.
                 IN A 123.123.4.56
 ;  IN MX 1 relay.iadmin.vip.
 ; relay IN A 77.88.99.11
                 IN MX 1 ASPMX.L.GOOGLE.COM.
                 IN MX 5 ALT1.ASPMX.L.GOOGLE.COM.
                 IN MX 5 ALT2.ASPMX.L.GOOGLE.COM.
                 IN MX 10 ASPMX2.GOOGLEMAMA.COM.
                 IN MX 10 ASPMX3.GOOGLEMAMA.COM.
                 IN MX 10 ASPMX4.GOOGLEMAMA.COM.
                 IN MX 10 ASPMX5.GOOGLEMAMA.COM.
                 IN TXT "v = spf1 include: aspmx.googlemail.com ~ all"
 mail IN CNAME ghs.google.com.
 calendar IN CNAME ghs.google.com.
 start IN CNAME ghs.google.com.
 docs IN CNAME ghs.google.com.
 _xmpp-server._tcp.iadmin.vip.  IN SRV 5 0 5269 xmpp-server.l.google.com.
 _xmpp-server._tcp.iadmin.vip.  IN SRV 20 0 5269 xmpp-server1.l.google.com.
 _xmpp-server._tcp.iadmin.vip.  IN SRV 20 0 5269 xmpp-server2.l.google.com.
 _xmpp-server._tcp.iadmin.vip.  IN SRV 20 0 5269 xmpp-server3.l.google.com.
 _xmpp-server._tcp.iadmin.vip.  IN SRV 20 0 5269 xmpp-server4.l.google.com.
 _jabber._tcp.iadmin.vip.  IN SRV 5 0 5269 xmpp-server.l.google.com.
 _jabber._tcp.iadmin.vip.  IN SRV 20 0 5269 xmpp-server1.l.google.com.
 _jabber._tcp.iadmin.vip.  IN SRV 20 0 5269 xmpp-server2.l.google.com.
 _jabber._tcp.iadmin.vip.  IN SRV 20 0 5269 xmpp-server3.l.google.com.
 _jabber._tcp.iadmin.vip.  IN SRV 20 0 5269 xmpp-server4.l.google.com.
 www IN CNAME iadmin.vip.
 ww IN CNAME iadmin.vip.
 wwww IN CNAME iadmin.vip.


Dns_records table


The table is used to add arbitrary records to the zone and consists of the following fields:


For example, in order to add an entry in which the iadmin.vip domain zone will have third-party mail servers (not our mail and not gmail), but, say, relay.dc.ukrtel.net, you need to write the following line:


domainname
rectype
data
enabled
id
.iadmin.vip
MX
10 relay.dc.ukrtel.net.
one
680

We must remember that after this we need to increase the serial in the dns_domains domain zone.

Dns_subgmail table


The table serves to simplify the writing of zones in which there are several subdomains using Google Apps and consists of the following fields:


For example, in order to add an entry in which the iadmin.vip domain zone will have the sync subdomain with the Google Apps service, you need to write the following line:


iddomainnamesubdomainenable
56iadmin.vipsyncone

Then the domain zone will look like this:
 $ TTL 86400
 iadmin.vip.  IN SOA ns0.english.com.  ns1.english.com.  (
                 2010082001;  serial
                 10800;  refresh
                 3600;  retry
                 604800;  expire
                 86400);  minimum
                 IN NS ns0.english.com.
                 IN NS ns1.english.com.
                 IN A 77.88.99.11
 ;  IN MX 1 relay.iadmin.vip.
 ; relay IN A 123.123.4.56
                 IN MX 1 ASPMX.L.GOOGLE.COM.
                 IN MX 5 ALT1.ASPMX.L.GOOGLE.COM.
                 IN MX 5 ALT2.ASPMX.L.GOOGLE.COM.
                 IN MX 10 ASPMX2.GOOGLEMAMA.COM.
                 IN MX 10 ASPMX3.GOOGLEMAMA.COM.
                 IN MX 10 ASPMX4.GOOGLEMAMA.COM.
                 IN MX 10 ASPMX5.GOOGLEMAMA.COM.
                 IN TXT "v = spf1 include: aspmx.googlemail.com ~ all"
 mail IN CNAME ghs.google.com.
 calendar IN CNAME ghs.google.com.
 start IN CNAME ghs.google.com.
 docs IN CNAME ghs.google.com.
 _xmpp-server._tcp.iadmin.vip.  IN SRV 5 0 5269 xmpp-server.l.google.com.
 _xmpp-server._tcp.iadmin.vip.  IN SRV 20 0 5269 xmpp-server1.l.google.com.
 _xmpp-server._tcp.iadmin.vip.  IN SRV 20 0 5269 xmpp-server2.l.google.com.
 _xmpp-server._tcp.iadmin.vip.  IN SRV 20 0 5269 xmpp-server3.l.google.com.
 _xmpp-server._tcp.iadmin.vip.  IN SRV 20 0 5269 xmpp-server4.l.google.com.
 _jabber._tcp.iadmin.vip.  IN SRV 5 0 5269 xmpp-server.l.google.com.
 _jabber._tcp.iadmin.vip.  IN SRV 20 0 5269 xmpp-server1.l.google.com.
 _jabber._tcp.iadmin.vip.  IN SRV 20 0 5269 xmpp-server2.l.google.com.
 _jabber._tcp.iadmin.vip.  IN SRV 20 0 5269 xmpp-server3.l.google.com.
 _jabber._tcp.iadmin.vip.  IN SRV 20 0 5269 xmpp-server4.l.google.com.
 www IN CNAME iadmin.vip.
 ww IN CNAME iadmin.vip.
 wwww IN CNAME iadmin.vip.
 sync IN MX 1 ASPMX.L.GOOGLE.COM.
 sync IN MX 5 ALT1.ASPMX.L.GOOGLE.COM.
 sync IN MX 5 ALT2.ASPMX.L.GOOGLE.COM.
 sync IN MX 10 ASPMX2.GOOGLEMAIL.COM.
 sync IN MX 10 ASPMX3.GOOGLEMAIL.COM.
 sync IN MX 10 ASPMX4.GOOGLEMAIL.COM.
 sync IN MX 10 ASPMX5.GOOGLEMAIL.COM.
 sync IN TXT "v = spf1 include: aspmx.googlemail.com ~ all"
 mail.sync IN CNAME ghs.google.com.
 calendar.sync IN CNAME ghs.google.com.
 start.sync IN CNAME ghs.google.com.
 docs.sync IN CNAME ghs.google.com.
 _xmpp-server._tcp.sync.iadmin.vip.  IN SRV 5 0 5269 xmpp-server.l.google.com.
 _xmpp-server._tcp.sync.iadmin.vip.  IN SRV 20 0 5269 xmpp-server1.l.google.com.
 _xmpp-server._tcp.sync.iadmin.vip.  IN SRV 20 0 5269 xmpp-server2.l.google.com.
 _xmpp-server._tcp.sync.iadmin.vip.  IN SRV 20 0 5269 xmpp-server3.l.google.com.
 _xmpp-server._tcp.sync.iadmin.vip.  IN SRV 20 0 5269 xmpp-server4.l.google.com.
 _jabber._tcp.sync.iadmin.vip.  IN SRV 5 0 5269 xmpp-server.l.google.com.
 _jabber._tcp.sync.iadmin.vip.  IN SRV 20 0 5269 xmpp-server1.l.google.com.
 _jabber._tcp.sync.iadmin.vip.  IN SRV 20 0 5269 xmpp-server2.l.google.com.
 _jabber._tcp.sync.iadmin.vip.  IN SRV 20 0 5269 xmpp-server3.l.google.com.
 _jabber._tcp.sync.iadmin.vip.  IN SRV 20 0 5269 xmpp-server4.l.google.com.

Also, we must remember that after this we need to change the serial in the dns_domains domain zone.

Script


The script, based on the data stored in iadmin, writes configuration files for bind (Now it is on perl, it will most likely be rewritten in python later).
Sources posted on github

Source: https://habr.com/ru/post/111678/


All Articles