I currently have a Linode with a cPanel install that uses a local DNS server as a master and sets the Linode DNS servers up as slaves. This allows me to fully utilize Linode's redundant DNS setup along with cPanel's familiar interface.
Here is a Ruby script that will create slave zones on Linode's DNS server pointing to your Linode's IP address. It is very basic, but gets the job done. If you are running many websites on your cPanel install, I'd recommend optimizing it.
This script will remove all DNS zones on Linode that do not already exist in cPanel.
Make sure you have the Gems necessary:
Code:
gem install linode lumberg
Create the file
/scripts/rebuildlinodezones including your Linode and cPanel API keys:
Code:
#!/usr/bin/env ruby
############################################################################################
# SETUP:
# => gem install linode lumberg
############################################################################################
require 'lumberg'
require 'linode'
# Configuration information
CPANEL_KEY = "AABBCCDDEEFFGG"
LINODE_KEY = "AABBCCDDEEFFGG"
# Server IP
IP = `hostname -i`
############################################################################################
############################################################################################
# Connect to frameworks
cpanel = Lumberg::Whm::Server.new(:host => '127.0.0.1', :hash => CPANEL_KEY)
linode = Linode.new(:api_key => LINODE_KEY)
# Finds all DNS zones in cPanel/Linode
linode_zones = cpanel.dns.list_zones[:params]
cpanel_zones = linode.domain.list
# Iterate over each DNS Zone in Linode
linode_zones.each do |lin|
# Find any zones in cPanel with a matching domain
result = cpanel_zones.select { |cpl| cpl.domain == lin[:domain] }
# If there aren't any matches, create the zone in Linode
if result.count < 1 then
linode.domain.create(:domain => lin[:domain], :type => "slave", :master_ips => IP)
end
end
# Finds all DNS zones in cPanel/Linode
linode_zones = cpanel.dns.list_zones[:params]
cpanel_zones = linode.domain.list
# Iterate over each cPanel DNS Zone
cpanel_zones.each do |cpl|
# Find any Linode zones with the same domain
result = linode_zones.select { |lin| lin[:domain] == cpl.domain }
# If there aren't any matches, delete the zone from Linode
if result.count < 1 then
linode.domain.delete(:domainid => cpl.domainid)
end
end
Make sure it's executable:
Code:
chmod +x /scripts/rebuildlinodezones
Make sure you have named.conf setup to allow Linode nameservers to AXFR:
Code:
allow-transfer {
69.164.199.240;
69.164.199.241;
69.164.199.242;
69.93.127.10;
65.19.178.10;
75.127.96.10;
207.192.70.10;
109.74.194.10;
};I currently set up this script to run from these hooks to automate the zone creation:
(NOTE: You should probably rewrite the script to selectively add and delete zones rather than completely rebuilding all entries, as this is pretty inefficient but gets the job done)Code:
ln -s /scripts/rebuildlinodezones /scripts/postwwwacct
ln -s /scripts/rebuildlinodezones /scripts/postkillacct
ln -s /scripts/rebuildlinodezones /usr/local/cpanel/hooks/addondomain/addaddondomain
ln -s /scripts/rebuildlinodezones /usr/local/cpanel/hooks/addondomain/deladdondomain
ln -s /scripts/rebuildlinodezones /usr/local/cpanel/hooks/subdomain/addsubdomain
ln -s /scripts/rebuildlinodezones /usr/local/cpanel/hooks/subdomain/delsubdomain
ln -s /scripts/rebuildlinodezones /usr/local/cpanel/hooks/park/park
ln -s /scripts/rebuildlinodezones /usr/local/cpanel/hooks/park/unpark
After creating the hooks, be sure to run:
Code:
/usr/local/cpanel/bin/register_hooks
Now you'll have Linode's DNS server automatically update whenever you create or destroy a DNS zone on your cPanel server! Cool! I even set up my custom nameservers to point to the Linode IPs so it appears as if I'm running my own redundant and highly available nameservers
(of course anyone curious enough will be able to figure out they're hosted at Linode)