Edit all records for 1 domain at once

myH2Oservers

Verified User
Joined
Mar 13, 2006
Messages
214
Location
Netherlands
When i change a website from one server to another, i need to add all standard dns records with the new IP, and then delete all the old ones.

Is it possible to create a function which can simulate the ipswap.sh function, but then only for 1 domain? 1st box has the standard IP, in the 2nd box you need to fill in the new IP, press the swap button and all standard (or all records with that IP) gets swapped to the new IP.
 
When you restore the backup on the second server you're given an option "- Use the IP stored in the backup" or "- Use the IP from the list:". Use the latter option and set it to the IP of your choice.
 
Or from the command line, as root, in the /var/named directory:
Code:
perl -i.bak -p -e 's/209.237.253.164/206.132.219.2/ig' example.net.db
(with your own old and new IP#s of course)

Jeff
 
When you restore the backup on the second server you're given an option "- Use the IP stored in the backup" or "- Use the IP from the list:". Use the latter option and set it to the IP of your choice.
I'm not talking about restoring ;)

I use 1 of my webservers as the main DNS server, when i move website Y from my own webserver to, for example, a dedicated server of a customer i need to change all the records for that domain.

And of course it can be done with the command line, but i won't give my customers shell access, and for myself there must be a faster way ;)
 
For your customers: I don't think it's a good idea to let your customers change everything at once; too easy to break DNS all at once ;).

For you, an easier way? As admin, remove the DNS zone, and recreate it immediately, which will create all default entries with the new server main IP#.

Jeff
 
I'm not talking about restoring ;)

I use 1 of my webservers as the main DNS server, when i move website Y from my own webserver to, for example, a dedicated server of a customer i need to change all the records for that domain.

And of course it can be done with the command line, but i won't give my customers shell access, and for myself there must be a faster way ;)

Use the API. We use it to change IP's for certain domains who are hosted on external servers from within our customer portal. We have build it in a way, so we can choose which records we want to change (web, mail or all).

This eventually is a much more powerful tool than using DirectAdmin to change DNS records. We detect changes to outside servers so it will change the MX tickbox as well (use this server to handle mail, rings a bell? ;-)). This saves us lots of time. This isn't included in the functions though, that's outside work.

Besides that, we're changing the TXT record accordingly when needed. Just some things you might want to think about if you're building a similar solution.

Here are the functions we use to add and remove records, you can of course combine them to a changerecord() function. It's using the normal HTTP Socket Code as provided on the forums here to connect to the API.

PHP:
function addrecord($domain, $type, $name, $ip)
{
	global $sock;
	$sock->query('/CMD_API_DNS_ADMIN', array('domain' => $domain, 'action' => 'add', 'type' => $type,	'name' => $name, 'value' => $ip));
	$result = $sock->fetch_body();
						
	$returncode = explode("&", $result);
	foreach($returncode as $key => $return)
	{
		$message 		= explode("=", $return);
							
		if($message[0] == "error" && $message[1] != "0")
		{
			return $result;								
		}											
	}
						
	return "* Adding {$type} record '{$name}'";
}	

function delrecord($domain, $record, $type = 'A')
{
	global $sock;
	if($type == "A")
	{
		$sock->query('/CMD_API_DNS_ADMIN', array('domain' => $domain, "action" => "select", "arecs0"	=> "name=" . $record));
	}
	if($type == "TXT")
	{
		$sock->query('/CMD_API_DNS_ADMIN', array('domain' => $domain, "action" => "select", "txtrecs0" => "name=" . $record));
	}
	$result = $sock->fetch_body();
						
	$returncode = explode("&", $result);
	foreach($returncode as $key => $return)
	{
		$message 		= explode("=", $return);
					
		if($message[0] == "error" && $message[1] != "0")
		{
			return $result;								
		}											
	}
						
	return "* Removing {$type} record '{$record}'";					
}
 
Last edited:
getUP, I never even considered using the API for managing DNS:

We've been managing DNS (including DNS for thousands of domains at the same IP#, for a domain holding company) for years, and we've gotten fairly good at scripting, including scripting one-line edits using perl. Also at creating single zone files for multiple domains, which Cricket Liu describes in the O'Reillly DNS and Bind book.

And we did it long before there was any kind of hosting automation; we also wrote our own hosting automation system years ago, but it was entirely command line driven. Do you (or anyone else for that matter) remember a company: 9Net Avenue (much better known than we were at the time)?

We, like they, answered change request phone-calls with humans, and then scheduled scripts to run (similarly to the way the DirectAdmin task queue runs) to make configuration changes.

I like DirectAdmin a lot better ;).

Since DirectAdmin DNS doesn't modify any other files besides the named.conf file and the zone files, there's no reason to use the API, though it's certainly acceptable to do so.

Jeff
 
Yea, I agree, it all depends on the situation. I prefer 1 line perl commands most of the time as well.

However, the functions I've posted are part of a customer portal. We have customers with several servers who, in case of an error or faulty server, move some domains between them. Since they don't have access to the one-liners, the API does it's job perfectly.

It all depends on where you would need it for and how much time and effort you are willing to put into it ;-)
 
Back
Top