Overhead of DNS records on subdomains

darkshifty

Member
Oct 14, 2016
8
1
3
Netherlands
cPanel Access Level
Root Administrator
I have an automated subdomain creation on my server via the API, however a load (9 of them!) of overhead DNS is created with the creation of a new subdomain. How can i customize the DNS templates for subdomains that only an A record is added?


The following records are added which aren't needed:
www
default._domainkey
cpcalendars
webdisk
cpanel
webmail
cpcontacts
whm
and a SPF record.

With thanks
 

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,880
2,258
463
Hello,

Assuming you want to keep those subdomains for the primary domain names associated with the cPanel accounts, you could develop a custom script that manually removes those DNS records through the manipulation of the corresponding zone file in the /var/named/ directory. Then, configure that custom script to run as a post hook every time a new subdomain is added:

Guide to Standardized Hooks - Software Development Kit - cPanel Documentation

You can find the corresponding API function for a hook by enabling "Debug mode is on. The system displays information about every stage for every hookable event, even if no hooks exist for that stage." under the "Development" tab in "WHM >> Tweak Settings". Then, perform the specific action you want to hook into via cPanel or WHM, and watch the output in /usr/local/cpanel/logs/error_log.

For example, the following cPanel API 1 function is utilized when adding an Alias in cPanel:

Cpanel::Api1::Park::park

You can find documentation on hooks with cPanel functions at:

Guide to Standardized Hooks - Cpanel Functions - Software Development Kit - cPanel Documentation

Thank you.
 
  • Like
Reactions: darkshifty

darkshifty

Member
Oct 14, 2016
8
1
3
Netherlands
cPanel Access Level
Root Administrator
Hello,

Assuming you want to keep those subdomains for the primary domain names associated with the cPanel accounts, you could develop a custom script that manually removes those DNS records through the manipulation of the corresponding zone file in the /var/named/ directory. Then, configure that custom script to run as a post hook every time a new subdomain is added:

Guide to Standardized Hooks - Software Development Kit - cPanel Documentation

You can find the corresponding API function for a hook by enabling "Debug mode is on. The system displays information about every stage for every hookable event, even if no hooks exist for that stage." under the "Development" tab in "WHM >> Tweak Settings". Then, perform the specific action you want to hook into via cPanel or WHM, and watch the output in /usr/local/cpanel/logs/error_log.

For example, the following cPanel API 1 function is utilized when adding an Alias in cPanel:

Cpanel::Api1::Park::park

You can find documentation on hooks with cPanel functions at:

Guide to Standardized Hooks - Cpanel Functions - Software Development Kit - cPanel Documentation

Thank you.
Sounds good, i will have a look at that. Thanks!
 
  • Like
Reactions: cPanelMichael

darkshifty

Member
Oct 14, 2016
8
1
3
Netherlands
cPanel Access Level
Root Administrator
Sounds good, i will have a look at that. Thanks!
I've looked into it but i cant come to a viable solution, the only way with these hooks is removing records per line which isn't very attractive to program as i have to identify all the 9 records, remove them per line and add an A record.

Isn't there a way to adjust the template for subdomains or create a pre hook that uses such a template?

The documentation is very general and limited.
 

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,880
2,258
463
Hello,

Most of the subdomains you referenced are part of the proxy subdomains feature. They are automatically created as part of the following option under the "Domains" tab in "WHM >> Tweak Settings":

Proxy subdomain creation

Per it's description:

Automatically create cpanel, webmail, webdisk, cpcalendars, cpcontacts, and whm proxy subdomain DNS entries for new accounts. When this is initially enabled it will add appropriate proxy subdomain DNS entries to all existing accounts. (Use /scripts/proxydomains to reconfigure the DNS entries manually)

One potential alternative is to run a command like this in a custom script that runs as a post action hook during the addition of a new subdomain:

Code:
/scripts/proxydomains --domain=sub.domain.tld remove
Thank you.