Named/bind: is there a way to create an alias to a single IP?

Red Squirrel

[H]F Junkie
Joined
Nov 29, 2009
Messages
9,211
Going to be moving my online server to a new provider. There are multiple zones pointing to the same IP, when I switch to a new server/provider I then have to change that IP in each zone.

Is there a way to create some kind of alias so I only need to do it once? I use CNAMEs within a certain zone but you can't use CNAME across other zones and can't use it for the "main" record (ex: example.com). Is there any way to do this?

Also going from CentOS 5 to CentOS 6 in the process, so I'm hoping the syntax of the zone files did not change.
 
The right way to do it, since most zones are not all the same:
Code:
perl -pi -e 's/abc/XYZ/g' /var/named/zones/zonefile

where abc is the original IP and XYZ is the new IP.

you can put that in a bash script to do it for each of your zone files.


To answer your question in DNS terms:
DNAME is an alias, but it allows no other records below the level that it's at. If you just have a bunch of dummy zones that are all the same, DNAME will work.
If you put a DNAME at the zone apex, no subdomains will resolve. MX and NS and other RRs affecting the zone apex can be used.
 
Last edited:
Hmmm yeah DNAME would probably not work then.

Can I use that perl command with a wild card? ex: replace zonefile with just *? I suppose that could work if I can just do a mass replace.
 
It has to be done in a foreach loop (well, no it doesn't.. but bash doesn't work that way)
you can do xargs or a foreach or a for or find/-exec..

EDIT: actually, it does work with * .. perl can handle that argument.
 
Last edited:
I'll play around with scripting then. I just figured there was maybe a way within bind to do it. Eventually I do want to write a web based management system for this kind of stuff anyway so I wont have to do it all manually.
 
How similar are the zones? Do they all have the same records basically? You can write zones without hardcoding the zone name in it, so you could use one zone file for different zones and it would basically be relative to the zone name.

Like so:

Code:
$TTL 1D
@           SOA     ns1 hostmaster (
                    2014090301
                    3H
                    30M
                    2W
                    15M )
            NS      ns1
            MX 10   mx1
...

You could use this file for example.com and would have ns1.example.com and mx1.example.com. When used for example.net, the records become ns1.example.net and mx1.example.net etc.

And what do you mean by "can't use CNAME across other zones"? Of course you can reference any FQDN in a zone.

PS: When did the discussion change from CNAME to DNAME (2nd post)?
 
Last edited:
There's about 30 or so, they're not all the same but a lot of them are similar. I've done it by hand before but I was thinking there was a better way. I'll probably end up just scripting it.

Though if it's possible to use CNAMEs across zones I'll try that too... but when I had tried it, it did not work for the "main" record only the sub domains. What is the syntax for the main record? Typically it is this:

Code:
@                       IN      A       1.2.3.4

If I wanted to make that a cname to say, example.com, how would I do that?

Tried replacing A with CNAME and putting in the host but it fails to load. Does not really point to any specific error it just spits this out which does not really tell my anything:

Code:
Error in named configuration:
dns_master_load: zones/iceteks.net:18: iceteks.net: CNAME and other data
dns_master_load: zones/iceteks.net:18: iceteks.net: CNAME and other data
dns_master_load: zones/iceteks.net:18: iceteks.net: CNAME and other data
dns_master_load: zones/iceteks.net:18: iceteks.net: CNAME and other data
zone iceteks.net/IN: loading master file zones/iceteks.net: CNAME and other data
_default/iceteks.net/IN: CNAME and other data

Oddly, line 18 is not even where I did the change, that's just the SPF record.
 
It says that you can't have CNAME "and other data", i.e. your SPF record. You generally can't have @ as a CNAME.

What about just using $INCLUDE to include the common parts into each zone?
 
Oh ok, so I'd still have to go edit each zone anyway to change the IP for the @ record. I could probably make a common include file for the header portion though. Might do that.
 
I'm not sure I understand. You'd just have a file that contains
Code:
@ A <IP address>
and other similar records and $INCLUDE that in each zone.

Edit: You probably want to put the SOA into that file, too, so you don't end up changing a dozens serial numbers as well.
 
Oh right, I could include that part in the file too. I'll experiment with that on the new server as it wont be live.
 
Can you not do a "find and replace" on each file? It'd be super simple for 30 files.
 
Red Squirrel said:
Though if it's possible to use CNAMEs across zones I'll try that too... but when I had tried it, it did not work for the "main" record only the sub domains. What is the syntax for the main record? Typically it is this:

If I wanted to make that a cname to say, example.com, how would I do that?

Tried replacing A with CNAME and putting in the host but it fails to load.


You cannot put a CNAME at the zone apex. ("across zones" or "the main record")

You can put a DNAME at the zone apex, but it breaks all subdomains.
 
Back
Top