CNAME or A record?

Mark Elkins mje at posix.co.za
Wed Sep 28 19:02:08 UTC 2011


On Wed, 2011-09-28 at 16:19 +0200, feralert wrote:

> The thing is that i want users redirected to 'www.domain.com' even
> when they just type the domain name 'domain.com'.
> In order to do so I am not sure if its best to have one A RR for each
> or have an A RR for the domain and a CNAME RR pointing to 'domain.com'
> for 'www.domain.com'.
> 
> 
> domain.com           A            1.1.1.1
> www.domain.com   A            1.1.1.1
> 
> OR
> 
> domain.com           A            1.1.1.1
> www.domain.com   CNAME  domain.com

If named.conf is correctly set up with the domain name - then
you could use

$TTL 3600
@	IN	SOA	...the SOA info
	IN	NS	Nameserver record lines
	IN	A	1.1.1.1
www	IN	A	1.1.1.1

Last line can be converted to a CNAME...
www	IN	CNAME	domain.com.

When you include IPv6 addresses into the mix...
using a CNAME saves you entering the same IPv6 address twice - so then
there really is a saving - especially when you include other alternative
labels like 'mail', 'pop', 'smtp', 'ftp' - etc - do them all as CNAMES!

$TTL 3600
@	IN	SOA	...the SOA info
	IN	NS	Nameserver record lines
	IN	A	1.1.1.1
	IN	AAAA	2001:1:1::80
www	IN	CNAME	domain.com

What I think is your real problem....
Regardless of whatever which way you decide - apache will be given the
original name - DNS will not re-write that.. so you have to spell out
both names in your apache configuration files...

So (playing with virtual hosts)
NameVirtualHost 1.1.1.1

<VirtualHost 1.1.1.1>
  ServerName domain.com
  ServerAlias www.domain.com
  ...
</VirtualHost>

-and later for IPv6 - duplicate the above...
(this line next to the other "NameVirtualHost"
NameVirtualHost [2001:1:1::80]

<VirtualHost [2001:1:1::80]>
  ServerName domain.com
  ServerAlias www.domain.com
  ...
</VirtualHost>

-- 
Mark Elkins <mje at posix.co.za>
Posix Systems




More information about the bind-users mailing list