Add CNAME record in BIND zone file

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 as https://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 nor https://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 or https://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 and host1.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 both xyz1.com and host1.xyz1.com to point to. How to achieve this?


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