What is Subdomain?

Published Aug 26, 2024

What is a Subdomain?

A subdomain is an extension of your primary domain name. It is used to organize and navigate to different sections of your website. A subdomain is created by adding a prefix to your primary domain name, separated by a dot (e.g., blog.example.com where blog is the subdomain of the primary domain example.com).

Structure of a Subdomain

  • Top-Level Domain (TLD): The last segment of the domain name, such as .com, .net, .org.
  • Second-Level Domain (SLD): The main domain name registered with a domain registrar (e.g., example in example.com).
  • Subdomain: The prefix added to the main domain (e.g., blog in blog.example.com).

Where is a Subdomain Needed?

  1. Organizing Content: Separating different sections of a website, such as blog.example.com for a blog and shop.example.com for an online store.
  2. Testing and Development: Creating a staging environment for testing purposes, such as dev.example.com.
  3. Localization: Providing localized versions of a website, such as en.example.com for English and fr.example.com for French.
  4. Microsites: Launching separate, but related, microsites for specific campaigns or projects.
  5. Email: Managing email services, such as mail.example.com.

How to Configure Subdomains

Configuring subdomains involves setting up DNS records with your domain registrar or DNS hosting provider. Here’s a step-by-step guide to configure subdomains, using GoDaddy as an example:


Step 1: Log in to Your Domain Registrar’s Management Console


Log in to your account on your domain registrar’s website (e.g., GoDaddy).

Step 2: Access DNS Management

Navigate to the My Products page to view your domain names.
Locate the domain you want to configure and click DNS next to it. This will take you to the DNS Management page.


Step 3: Add a Subdomain

In the DNS Management page, locate the Records section.
Click Add to create a new DNS record.

Step 4: Configure the A Record for the Subdomain

Type: Select A (Address) from the dropdown menu.
Host: Enter the subdomain prefix (e.g., blog to create blog.example.com).
Points to: Enter the IP address of the server where the subdomain will be hosted.
TTL (Time to Live): Set a TTL value, such as 600 seconds (10 minutes).
Example:
Type: A
Host: blog
Points to: 192.0.2.1
TTL: 600 or 3500

Click Save to create the subdomain.

Step 5: Now Verify the Subdomain

DNS changes can take some time to propagate across the Internet. You can use various tools to check if the subdomain has been correctly set up.
Tools to Verify DNS Propagation
1 - WhatsMyDNS.net: Enter your subdomain to see the current DNS records from various locations around the world.
2 - nslookup: Use the nslookup command in your terminal or command prompt to query the DNS records.
Example: open Terminal in system run the command
 - nslookup blog.example.com

Example: Configuring a Subdomain in AWS Route 53
If you are using AWS Route 53, follow these steps:
1. Log in to the AWS Management Console
Navigate to the Route 53 Dashboard.
2. Select Your Hosted Zone
Click on Hosted zones and select the domain you want to configure.
3. Create a New Record

  1. Click Create record.
  2. Select Simple routing.
  3. Click Next.
  4. Configure the record:
  • Record name: Enter the subdomain prefix (e.g., blog).
  • Record type: A (Address)
  • Value: Enter the IP address of hosting server (e.g., 192.0.2.1).
  • TTL: Set a TTL value (e.g., 600 seconds).

Example:
Record name: blog
Record type: A
Value: 192.0.2.1
TTL: 600

Click Create records.
Example: Using AWS CLI to Create a Subdomain
For those who prefer using the AWS CLI, here are the commands to create a subdomain:


Create an A Record
 

aws route53 change-resource-record-sets --hosted-zone-id Z3AADJGX6KTTL2 --change-batch '{

  "Comment": "Creating subdomain blog.example.com",

  "Changes": [{

    "Action": "UPSERT",

    "ResourceRecordSet": {

      "Name": "blog.example.com",

      "Type": "A",

      "TTL": 600,

      "ResourceRecords": [{"Value": "192.0.2.1"}]

    }

  }]

}'