📜 ⬆️ ⬇️

Module for adding domains from Directadmin to DNSmanager

There was a question about creating a DNS cluster based on DNSmanager. Some servers are running directadmin.
A small digression on the logic of dnsmanager:
- when creating a reseller with its NS servers, a database with the same name is created;
- all reseller users write domains to the reseller database (the name is only their username and password), as a result, each user has their own domains. This is necessary in order for someone not to add a domain (which already exists) on another server (the domain will be added on the server, and the cluster will not leave in the DNS as there is already such a domain, but if all servers use the same login and password , then when deleting - the domain will be deleted).

Based on this, a rule arises - each server must have its own login and password.

To import domains when they are created, renamed, deleted from directadmin to dns manager, you need:
1. On the server with the directmin look at the named.conf config.
In options {
add:
allow-transfer { IP1; IP2; IP3; IP4; }; notify yes; also-notify { IP1; IP2; IP3; IP4; }; allow-recursion { localnets; }; 

IP1; IP2; IP3; IP4; - A list of IP from which you can pick up zones.
I recommend adding both the main IP DNSmanager and the IP on which the DNS will be running.
2. On the server with directmin look in:
 cd /usr/local/directadmin/data/templates/custom 

The zone.conf file, there is something like:
 zone "|DOMAIN|" { type master; allow-transfer { IP1; }; notify yes; file "|PATH|/|DOMAIN|.db"; }; 

And if necessary, we add our new IPs there:
 zone "|DOMAIN|" { type master; allow-transfer { IP1; IP2; IP3; IP4; }; notify yes; file "|PATH|/|DOMAIN|.db"; }; 

IP1; IP2; IP3; IP4; - A list of IP from which you can pick up zones.
I recommend adding both the master IP DNSmanager and the IP on which the DNS (IP reseller) will run.

3. On the server with the directmin, distort the named:
Freebsd:
 /etc/rc.d/named/restart 

Linux:
 /etc/init.d/named restart 

4. On the server with the directmin write 2 scripts.
The first:
 cd /usr/local/etc mkdir dadnstodnsmanager cd dadnstodnsmanager touch add-domain.sh mcedit add-domain.sh 

We insert there
 #!/bin/sh DNSMGRIP="IP_DNSmanager" USERDNS="_" PASSUSERDNS="_" MASTERIP="IP__(_IP_)" /usr/local/bin/curl --insecure https://${DNSMGRIP}:1500/dnsmgr\?authinfo=${USERDNS}:${PASSUSERDNS}\&out=xml\&func=domain.edit\&dtype=slave\&master=${MASTERIP}\&name=$1\&sok=ok >/dev/null 2>&1 

Or just immediately insert the values:
 #!/bin/sh /usr/local/bin/curl --insecure https://IP:1500/dnsmgr\?authinfo=:\&out=xml\&func=domain.edit\&dtype=slave\&master=_IP\&name=$1\&sok=ok 

Further:
 chmod +x /usr/local/etc/dadnstodnsmanager/add-domain.sh 

The second script:
 cd /usr/local/etc mkdir dadnstodnsmanager cd dadnstodnsmanager touch delete-domain.sh mcedit delete-domain.sh 

We insert there:
 #!/bin/sh DNSMGRIP="IP_DNSmanager" USERDNS="_" PASSUSERDNS="_" MASTERIP="IP__(_IP_)" /usr/local/bin/curl --insecure https://${DNSMGRIP}:1500/dnsmgr\?authinfo=${USERDNS}:${PASSUSERDNS}\&elid=$1\&func=domain.delete >/dev/null 2>&1 

Or just immediately insert the values:
 #!/bin/sh /usr/local/bin/curl --insecure https://IP:1500/dnsmgr\?authinfo=:\&elid=$1\&func=domain.delete >/dev/null 2>&1 

Further:
 chmod +x /usr/local/etc/dadnstodnsmanager/delete-domain.sh 

')
5. Both scripts are ready, we check that we were not mistaken:
 cd /usr/local/etc/dadnstodnsmanager/ ./add-domain.sh testmeserver1.com 

We are looking at what the domain appeared in DNSmanager. It is best to do this with the domain that is on the server and it has DNS records.
If the domain appeared in DNSmanager and the records were transferred, then everything is fine.
If the domain has appeared but no records are running on DNSmanager
 dig @IP_MASTER_ testmeserver1.com axfr 


If we get:
 ; <<>> DiG VVV <<>> @IP_MASTER_ testmeserver1.com axfr ; (1 server found) ;; global options: +cmd ; Transfer failed. 

The zone transfer is incorrectly configured (see p. 1-2), or the named is not restarted after the changes.
We look at the logs and fix it until the server returns
 #dig @IP_MASTER_ testmeserver1.com axfr ; <<>> DiG VVV <<>> @IP_MASTER_ testmeserver1.com axfr ; (1 server found) ;; global options: +cmd testmeserver1.com. 14400 IN SOA ns1.mydnsserver.com. hostmaster.testmeserver1.com. 2013111400 14400 3600 1209600 86400 testmeserver1.com. 14400 IN MX 10 mail.testmeserver1.com. testmeserver1.com. 14400 IN TXT "v=spf1 a mx ip4:IP_MASTER_ ~all" testmeserver1.com. 14400 IN A IP_ testmeserver1.com. 14400 IN NS ns1.mydnsserver.com. testmeserver1.com. 14400 IN NS ns2.mydnsserver.com. testmeserver1.com. 14400 IN NS ns3.mydnsserver.com. ftp.testmeserver1.com. 14400 IN A IP_ localhost.testmeserver1.com. 14400 IN AAAA ::1 localhost.testmeserver1.com. 14400 IN A 127.0.0.1 mail.testmeserver1.com. 14400 IN A IP_ pop.testmeserver1.com. 14400 IN A IP_ smtp.testmeserver1.com. 14400 IN A IP_ www.testmeserver1.com. 14400 IN A IP_ testmeserver1.com. 14400 IN SOA ns1.mydnsserver.com. hostmaster.testmeserver1.com. 2013111400 14400 3600 1209600 86400 ;; Query time: 1 msec ;; SERVER: IP_MASTER_#53(IP_MASTER_) ;; WHEN: Fri Nov XX XX:XX:XX XXXX ;; XFR size: 15 records (messages 1, bytes 424) 

If everything is fine, check the second script:
 cd /usr/local/etc/dadnstodnsmanager/ ./delete-domain.sh testmeserver1.com 

We check that the domain is deleted from DNSmanager.

6. There is a set of additional scripts in the directmin run before or after certain events.
They lie in:
/ usr / local / directadmin / scripts / custom

We are interested:
domain_change_post.sh
domain_create_post.sh
domain_destroy_post.sh
domain_pointer_create_post.sh
domain_pointer_destroy_post.sh
subdomain_create_post.sh
subdomain_destroy_post.sh
user_create_post.sh

If not, then you need to create.

Let's take turns:

domain_change_post.sh runs after the domain is renamed.
Rule it - add:
 /usr/local/etc/dadnstodnsmanager/delete-domain.sh.sh $domain /usr/local/etc/dadnstodnsmanager/add-domain.sh $newdomain 


After renaming the old domain will be removed from the cluster, and the new one will be added.

domain_create_post.sh runs after the domain is created.
Rule it - add:
 /usr/local/etc/dadnstodnsmanager/add-domain.sh $domain 


domain_destroy_post.sh runs after the domain is deleted.
Rule it - add:
 /usr/local/etc/dadnstodnsmanager/delete-domain.sh $domain 


domain_pointer_create_post.sh runs after the domain pointer has been created.
Rule it - add:
 /usr/local/etc/dadnstodnsmanager/add-domain.sh $from 


domain_pointer_destroy_post.sh runs after creating the domain pointer domain.
Rule it - add:
 /usr/local/etc/dadnstodnsmanager/delete-domain.sh $from 


subdomain_create_post.sh runs after the subdomain is created.
Rule it - add:
 /usr/sbin/rndc reload $domain 


subdomain_destroy_post.sh runs after deleting the subdomain.
Rule it - add:
 /usr/sbin/rndc reload $domain 


user_create_post.sh runs after the user is created.
Rule it - add:
 /usr/local/etc/dadnstodnsmanager/add-domain.sh $from 


7. Perform a check.
7.1 Created a user with a domain.
7.2 Log in as a user and create a subdomain.
7.3 Logged in as a user and created a domain index.
7.4 Logged in as a user and created another domain2.
7.5 Logged in as a user and renamed domain2.
7.6 Logged in as a user and deleted the subdomain.
7.7 Logged in as a user and deleted the domain index.
7.8 Logged in as a user and deleted domain2.
7.9 Delete user.
After each item, check what is sent to dnsmanager.

If all the tests have passed successfully you can be put into operation.

If you plan to use only one dnsmanager (on the master), then you can simply set up database replication and raise pds to the rest of the server NAs, then when the domain or its records change, the hosting server will send the changes to the master server, and from there the changes will be sent to slave server

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


All Articles