This article explains how to configure A and AAAA records in DNS, including steps for adding records and testing DNS resolution.
In this lesson, we will explore how to configure A and AAAA records in DNS. While the demo will focus on A records, configuring AAAA records follows an identical process—the only difference is that AAAA records map domain names to IPv6 addresses instead of IPv4.An A record maps a domain name to an IPv4 address by using a 4-byte address field in DNS packets, whereas a AAAA record maps a domain name to an IPv6 address with a 16-byte address field. Additionally, DNS packet headers include flags to identify the type of each record.
Before updating the DNS zone file, determine the IP address for node02. Since the IP address may change in each playground session, run the following command to capture its current IPv4 address:
Copy
bob@node01 ~ > ping node02PING node02 (192.5.180.8) 56(84) bytes of data.64 bytes from sandbox-ubuntu-multi-node-tyqrvp25f4w255rv_vm02.1.lej1m5c8m0xsx1upftq3psgz.sandbox-ubuntu-multi-node-tyqrvp25f4w255rv_k: icmp_seq=1 ttl=64 time=0.070 ms64 bytes from sandbox-ubuntu-multi-node-tyqrvp25f4w255rv_vm02.1.lej1m5c8m0xsx1upftq3psgz.sandbox-ubuntu-multi-node-tyqrvp25f4w255rv_k: icmp_seq=2 ttl=64 time=0.077 ms
With the IP address in hand, open your DNS zone file and add an A record to map node02 to its current IPv4 address:
Copy
$TTL 300@ IN SOA ns1.my.kodekloudlab.com. admin.my.kodekloudlab.com. ( 2 ; Serial 604800 ; Refresh 86400 ; Retry 2419200 ; Expire 604800 ) ; Negative Cache TTL@ IN NS ns1.my.kodekloudlab.com.ns1 IN A 127.0.0.1node02 IN A 192.5.180.8
After saving your changes, restart BIND9 to update the configuration.
For many web deployments, you may want the apex domain (e.g., my.kodekloudlab.com) to resolve directly to your server’s IP address. This is especially useful when hosting a web server. To do so, update your zone file so that the apex domain uses the at symbol (@) instead of an explicit subdomain:
Open the zone file:
Copy
bob@node01 ~ ➜ sudo vi /etc/bind/db.my.kodeloudlab.com
Next, update the zone configuration to set the apex domain as follows:
Copy
$TTL 300@ IN SOA ns1.my.kodekouldab.com. admin.my.kodekouldab.com. ( 2 ; Serial 604800 ; Refresh 86400 ; Retry 2419200 ; Expire 604800 ; Negative Cache TTL)@ IN NS ns1.my.kodekouldab.com.ns1 IN A 127.0.0.1@ IN A 192.5.180.8
Restart BIND9 once again and confirm that the apex domain resolves correctly:
Copy
bob@node01 ~ ➜ sudo vi /etc/bind/db.my.kodekloudlab.combob@node01 ~ ➜ sudo systemctl reload namedbob@node01 ~ ➜ dig @localhost my.kodekloudlab.com;; <<>> DiG 9.18.30-Ubuntu <<>> @localhost my.kodekloudlab.com;; (2 servers found);; global options: +cmd;; Got answer:;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 39219;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1;; OPT PSEUDOSECTION:; EDNS: version: 0, flags:; udp: 1232; COOKIE: 0a28c953013cb81010000006793426ba2a0f365488a04bf (good);; QUESTION SECTION:;my.kodekloudlab.com. IN A;; ANSWER SECTION:my.kodekloudlab.com. 300 IN A 192.5.180.8;; Query time: 0 msec;; SERVER: 127.0.0.1#53(localhost) (UDP);; WHEN: Fri Jan 24 02:34:03 EST 2025;; MSG SIZE rcvd: 92
With this configuration, accessing the apex domain (my.kodekloudlab.com) will directly reach the web server on node02.
If you plan to configure a AAAA record, use the same process as for the A record. The only difference is that you will be mapping the domain to an IPv6 address.
After successfully configuring the A record (and potentially a AAAA record), the next step is to configure a CNAME record. This record type allows you to alias one domain name to another. Detailed steps for configuring a CNAME record will be covered in the following lesson.For additional DNS configuration best practices and further reading, check out the DNS Concepts documentation.Happy DNS configuring!