The A, AAAA, and CNAME resource records

Authoritative name servers use the domain's zone file to translate names into IP addresses. The A and AAAA resource records map IP addresses with names. These records are also known as host records. You need to create host records for all resources available inside the domain. If you don't add a host record for the resource available within the domain, you cannot access it. Let's understand why this would happen.

  • To access a resource, you need the resource's IP address.
  • You can get the resource's IP address only from the authoritative name server.
  • The authoritative name server uses the zone file to tell the resource's IP address.
  • In the zone file, a host record maps a name and the IP address.
  • Since you did not add a host record for the resource, the authoritative name server fails to resolve the resource name into the IP address. Without knowing the IP address of a resource, you can not access it.

Adding or creating the A and AAAA records

A host record uses the following syntax.

name TTL class resource-record-type IP address

The following image shows the zone file of the example.com domain. It contains four host records.

a aaaa record

Let's understand the above records field-by-field.

The name Field

This field defines the name of the host or service whose IP address you want to make publicly accessible. There are two methods to specify a name in this field. These methods are FQDN and relative. In the FQDN method, you type the complete name of the host or service. It includes the names of all parent domains. It always ends with a dot. In the relative method, you type only the hostname or the short name of the host or service. You don't need to add the parent domain's name to it. It never ends with a dot.

Regardless of the method you use to specify the name in this file, DNS always processes the given name in the FQDN format. If you specify an FQDN name, it uses the name as it is. If you provide a relative name, DNS converts it into the FQDN name using the $ORIGIN directive's value.

The $ORIGIN directive is variable. Administrators use it to save the domain's name. In our example zone file, all host records are defined using the relative name. To convert these names into FQDN names, DNS will use the $ORIGIN directive's value.

name field in the zone file

The TTL Field

This field defines how long other name servers and resolver systems can cache this record. After this time, they need to fetch this record again. If you leave this field empty, DNS uses the value of the $TTL directive. The $TTL directive defines the default TTL value. If you leave the TTL field empty in any record, it uses the $TTL directive's value in that field.

ttl field in the zone file

The class type Field

This field defines the class type of this record. There are three classes: IN, CH, and HS. Currently, only the IN class is used. The CH and HS classes were used when the Internet was an in-house project in the MiT lab. CH stands for CHAOS. It is an MIT LAN protocol. HS stands for Hesiod. It is an information service used at MIT. IN stands for the Internet that we use today.

The resource-record-type Field

This field defines the type of record. The A record maps an IPv4 address with the name of a host or a service. The AAAA record maps an IPv6 address with the name of a host or a service.

The IP address Field

This field defines the IP address we want to map with the name specified in the name field. There are two types of IP addresses: IPv4 and IPv6. The resource type A maps an IPv4 address with the domain name, whereas the resource type AAAA maps an IPv6 address.

In our example zone file, we mapped IPv4 addresses with names. If we map IPv6 addresses with names, the file will look like the following.

the ip address field

Mapping multiple IP addresses with a name

You can map multiple IP addresses to the same name. This feature allows you to run the same service on multiple hosts. Generally, administrators run critical services on more than one host for backup and redundancy purposes. For example, they can run a web service on two or more hosts. In that case, they must map their IP addresses with the web service.

Let's understand this feature through our example. Currently, in our example, the web service is available only on the host 192.168.0.3. Suppose we configure the web service on two additional servers whose IP addresses are 192.168.0.9 and 192.168.0.10. In that case, we need to add two more A records for these hosts.

assigning multiple IP addresses to a name

If you map multiple IP addresses with the same name, DNS provides an IP address for the name in a round-robin or random order. You can define this order by configuration directives.

Mapping multiple names with a single IP address

You can also map more than one name with a single IP address. You can use this feature when you run multiple services on the same host. For example, if you have a small website and use only a few email addresses for management and communication purposes, you can run the mail, web, and FTP services on the same server. This setup allows you to save the cost of additional servers.

Let's understand this feature through our example. Currently, in our example, all services are available on individual servers. Suppose we configure the mail, web (www), and FTP services on a single server whose IP address is 192.168.0.2. In this situation, we must map these services with the IP address 192.168.0.2.

multiple names to a single IP

The CNAME resource record type

The CNAME resource record type assigns an alias to the name of an existing host or service. It uses the following syntax.

alias-name TTL class resource-record-type canonical-name

In the above syntax, the TTL and class fields have the same meanings as the TTL and class fields have in the host records.

The alias-name field defines the name you want to use for the existing name specified in the canonical-name field.

The resource-record-type field defines the record type. The value CNAME indicates this record is an alias name for the existing name.

The canonical-name field defines the name you want to use to access the alias name specified in the alias-name field. This record type is used when you want to access a service or a host from another name. You can also use this record to hide your internal network structure from external users.

Let's understand it through our example. Suppose we run the web service on a host called myWebServer. In this situation, we can map the name www (web service) with the name myWebServer. After this, DNS will translate the name www into the IP address of myWebServer. Users will access the web service running on the IP address of myWebServer by using the name www.

The following image shows how to add a CNAME for the web service in our example zone file.

the cname record

Addressing a website with or without www

Generally, administrators configure a web server to serve websites with and without the www. This setup needs a CNAME record in the zone file for the web service. To achieve this goal, add a host (A) record for the domain name and then configure the www as the alias name for that domain name.

Let's understand this through our example. In our example, the domain name is example.com. It hosts a website we want to access using both names: www.example.com and example.com.

In this case, first, we will create a host record for the domain name. Then, we will configure www as the alias name for the domain name.

The following image shows how to add both records.

accessing a website with or without www

A zone file only translates names into IP addresses. It does not run or provide any other service. If you add an alias name for a service, you must configure that service to respond on both canonical (actual) and alias names. In the previous example, you must configure the webserver to respond to both names: www.example.com and example.com.

Conclusion

DNS uses zone files to translate names into IP addresses. Zone files use resource records to map names and IP addresses. There are various types of resource records. In this tutorial, I explained how to create and manage A, AAAA, and CNAME resource record types.

ComputerNetworkingNotes Linux Tutorials The A, AAAA, and CNAME resource records

We do not accept any kind of Guest Post. Except Guest post submission, for any other query (such as adverting opportunity, product advertisement, feedback, suggestion, error reporting and technical issue) or simply just say to hello mail us ComputerNetworkingNotes@gmail.com