Add CNAME record in BIND zone file
Solution 1
CNAME
records cannot coexist with any other record type, with a few rare exceptions. In your case, the same domain already has SOA
and NS
records (just like the zone apex always has).
As a result it's likely that BIND has completely refused to load the zone file. (But you'd only know for sure by actually checking BIND's error logs.)
In other words, it's not allowed to have a CNAME
at zone apex, and you will have to manually copy the IP addresses as A
/AAAA
records.
In the future, DNS might standardize ANAME
pseudo-records which allow the IP addresses to be aliased without full CNAME semantics. (These are currently offered by some DNS hosting services as a custom addition.) See here, here, or here.
Solution 2
You're doing it backwards. Don't set the domain name as a CNAME for a subdomain. Set the subdomain (host1) as a CNAME for the domain (xyz1.com).
Use @ to indicate the root domain (xyz1.com):
;192.168.56.0/24 - A records
@ IN A 192.168.56.17
host1.xyz1.com. IN CNAME xyz1.com.
host2.xyz1.com. IN A 192.168.56.18
Related videos on Youtube
None
Updated on September 18, 2022Comments
-
None over 1 year
I have set up a virtual private network using virtualbox with a DNS server named:
dns1.xyz1.com
. I have a webs server named:xyz1.com
.I want to use my DNS server to resolve the IP address of the website. I configured the forward zone file as follows:
$TTL 604800 @ IN SOA dns1.xyz1.com. admin.xyz1.com. ( 13 ; Serial 604820 ; Refresh 86600 ; Retry 2419600 ; Expire 604600 ) ; Negative Cache TTL ; name servers - NS records IN NS dns1.xyz1.com. IN NS dns2.xyz1.com. ; name servers - A records dns1.xyz1.com. IN A 192.168.56.13 dns2.xyz1.com. IN A 192.168.56.15 ; 192.168.56.0/24 - A records host1.xyz1.com. IN A 192.168.56.17 xyz1.com. IN CNAME host1.xyz1.com. host1.xyz1.com. IN TXT "some text" host2.xyz1.com. IN A 192.168.56.18
Before I add the CNAME record, I was able to type:
https://host1.xyz1.com
and the browser transfer me to the right web server.After I added the CNAME record (I want to browser to also translate
https://xyz1.com
to the same website ashttps://host1.xyz1.com
) but unfortunately, after adding the CNAME line as shown below, none of the addresses open the desired web server: neither:https://xyz1.com
norhttps://host1.xyz1.com
.xyz1.com. IN CNAME host1.xyz1.com.
FYI, here is the
named.conf.local
file content:zone "xyz1.com" { type master; file "/etc/bind/forward.xyz1.com"; }; zone "56.168.192.in-addr.arpa"{ type master; file "/etc/bind/reverse.xyz1.com"; };
The bottom line: I want to access the same webserver (same IP) using different names: either
https://xyz1.com
orhttps://host1.xyz1.com
. Can you tell me what's wrong in my CNAME record? How can I fix it?EDIT:
Thanks for the answers. But the problem still exist. I can not resolve this address: xyz.com and I need to point to a particular server using the names:
xyz.com
andhost1.xyz.com
.Based on some answers, I updated this part of my configuration file:
; 192.168.56.0/24 - A records @ IN A 192.168.56.7 host1.xyz1.com. IN CNAME xyz1.com. host1.xyz1.com. IN TXT "text here"
There is a pingable web server with the IP:
192.168.56.7
which I want bothxyz1.com
andhost1.xyz1.com
to point to. How to achieve this?-
user1686 about 6 yearsHas BIND sent any error messages to the system log?
-
user1686 about 6 yearsIf not the system logs, then please update the post with output of
named-checkzone xyz1.com xyz1.com
. You completely missed the part where "CNAME records cannot coexist with other records". -
Patrick Mevzek almost 4 years"But the problem still exist. " Start by giving the real names involved instead of fake ones which are a bad way to obfuscate things. Also
ping
is the wrong tool to troubleshoot DNS problems. you need to usedig
and carefully understand the difference between a recursive and an authoritative nameserver.
-
-
None about 6 yearsthanks. But did not help. I added some extra info under
edit
in my original post. It might help you to answer me. -
Timmy Browne about 6 yearsmy fault, i did'nt delete the TXT record you had when i copy pasted. i only swapped the CNAME. edit to reflect change. if it doesn't work, paste the error output