Skip to main content
This guide explains how to configure a CNAME record (canonical name) to point one domain name to another. CNAME records are typically used for subdomains (e.g., “www”) and must point to another domain name—not directly to an IP address or the apex (root) domain.

Step 1: Install and Start Nginx on Node-02

First, connect to Node-02 via SSH and install Nginx:
Once installed, start the Nginx service:
Verify that Nginx is running by curling localhost:
If you receive an HTML page, Nginx is active and ready to serve your web content.

Step 2: Update the DNS Zone File on Node-01

Next, log into Node-01 to update the DNS zone file with a new CNAME record. In this example, setting up a record for “www” means that accessing www.my.kodekloudlab.com will point to my.kodekloudlab.com. Remember to update the serial number in the SOA record whenever you modify the zone file. Open the zone file using your preferred editor:
The DNS zone file should look like this:

Step 3: Update the Nameserver Configuration

After editing the zone file, update your nameserver configuration. Editing the resolv.conf file ensures that the correct nameserver entry is in place. For instance, in a KodeKloud playground the file might initially look like this:
Before making any modifications, it is recommended to back up your original nameserver information. Then, comment out the existing nameserver line if needed:
Always back up configuration files before making changes to ensure you can roll back if necessary.
After updating the configuration, restart BIND9 to apply the changes:

Step 4: Testing the CNAME Record

Now, test the configuration by curling the service via the CNAME:
You should see the typical Nginx welcome page similar to the following:
This confirms that the CNAME record in the “my.kodekloudlab.com” zone is resolving as expected.

Additional Consideration: Amazon Route 53 and CNAME Records

A unique characteristic of Amazon Route 53 is that it supports alias records for CNAMEs. This means you can point directly to AWS resources like S3 buckets or Elastic Load Balancers—even at the apex of a domain—a feature not supported by traditional CNAME records.

Conclusion

This guide demonstrated how to set up a CNAME record for subdomains using a combination of Nginx and BIND. Following these steps ensures that your subdomain (www.my.kodekloudlab.com) correctly resolves to your main domain. By understanding this process, you can manage your DNS configurations efficiently for improved web service management. Happy configuring!

Watch Video