Hjälpcentral

Subdomain Setup & DNS Configuration

Setting up subdomains and configuring DNS properly is essential for creating a robust, organized online presence. Whether you’re building a complex website with different services, managing multiple regions, or just want to create a simple subdomain for a blog or store, understanding how to configure DNS for subdomains is key to ensuring they work smoothly. This guide will walk you through the subdomain setup process, the necessary DNS configuration, and troubleshooting common issues related to subdomains.

What is a Subdomain?

A subdomain is a domain that is part of a larger primary domain. It allows you to organize your website or services by dividing the content into distinct sections without needing to purchase separate domain names. Subdomains are commonly used for organizing different parts of a website, pointing to separate servers or services, or creating regions (e.g., us.example.com for a U.S.-based service or shop.example.com for an online store).

Common Uses of Subdomains:

  • Region-based Subdomains: For targeting different countries or regions (e.g., uk.example.com, de.example.com).
  • Service-based Subdomains: For separating different services (e.g., blog.example.com, shop.example.com).
  • Application or Platform Subdomains: For app-related subdomains (e.g., app.example.com, mail.example.com).
  • Development or Testing Subdomains: For staging or testing purposes (e.g., dev.example.com, staging.example.com).

Setting Up a Subdomain

Setting up a subdomain involves both the domain registrar and DNS server. Here’s how to do it step-by-step.

 Access Your Domain’s DNS Management Panel

To start, log in to your domain registrar’s account (such as GoDaddy, Namecheap, or Google Domains) or your DNS hosting provider’s dashboard (e.g., Cloudflare, AWS Route 53, or your web hosting control panel like cPanel or Plesk).

Create a Subdomain Record in DNS

A subdomain is created through the DNS zone file for your domain. To do this, you need to add an A record, CNAME record, or MX record depending on the type of subdomain you're setting up.

A Record

If you want the subdomain to point directly to an IP address (e.g., for a web server or custom service), you should create an A record.

For example, to set up a subdomain blog.example.com, the A record would look like:

Name Type Value TTL
blog A 192.0.2.1 3600

In this case:

  • Name: blog (the subdomain name)
  • Type: A (points to an IP address)
  • Value: 192.0.2.1 (the IP address where the subdomain should resolve)
  • TTL: 3600 seconds (1 hour) — this defines how long DNS servers should cache the record.
CNAME Record

Alternatively, if your subdomain should point to another domain or subdomain (i.e., aliasing it), use a CNAME (Canonical Name) record. This is commonly used for pointing to a subdomain on a different server or platform.

For example, to point shop.example.com to store.exampleplatform.com, you would create a CNAME record:

Name Type Value TTL
shop CNAME store.exampleplatform.com 3600

In this case:

  • Name: shop (the subdomain name)
  • Type: CNAME (points to another domain)
  • Value: store.exampleplatform.com (the domain where the subdomain should resolve)
  • TTL: 3600 seconds (1 hour).
MX Record

If you are configuring an email service for a subdomain (e.g., mail.example.com), you will need to create an MX (Mail Exchanger) record pointing to the mail server handling emails for that subdomain.

For example, for mail.example.com to use Google’s mail servers, the MX record might look like:

Name Type Value Priority TTL
mail MX ASPMX.L.GOOGLE.COM 10 3600
  MX ALT1.ASPMX.L.GOOGLE.COM 20 3600
  • Priority: Determines the order of mail servers used. Lower numbers have higher priority.

Test the Subdomain

After creating the necessary DNS records, it’s crucial to test if the subdomain resolves correctly. You can use command-line tools like nslookup or dig, or online tools like DNSstuff or MXToolbox to check if the subdomain is resolving to the correct destination.

Example with nslookup:

nslookup blog.example.com

This command will return the IP address or the CNAME target that the subdomain resolves to, confirming that DNS is correctly configured.

Configuring DNS for Subdomains

Proper DNS configuration is crucial for the functioning of subdomains. Below are additional configuration options and considerations to ensure your subdomains are set up correctly.

TTL (Time To Live) Settings

TTL determines how long DNS records are cached by DNS servers and browsers before checking for an updated version. A shorter TTL value means that changes to DNS records propagate faster but can increase DNS lookup times. A longer TTL value reduces DNS lookups but delays changes.

For subdomains that require frequent updates (e.g., a development subdomain or test server), use a shorter TTL (e.g., 300 seconds). For stable subdomains like www.example.com or mail.example.com, a longer TTL (e.g., 86400 seconds) is often appropriate.

Subdomain Delegation

In some cases, a subdomain might need to be handled by a different DNS server entirely (e.g., for a third-party service or hosting provider). To delegate a subdomain, create NS (Name Server) records for that subdomain, pointing to the DNS server responsible for managing it.

For example, if blog.example.com is handled by a different server, you would create the following NS record:

Name Type Value TTL
blog NS ns1.bloghost.com 3600
  NS ns2.bloghost.com 3600

This tells DNS resolvers to look at ns1.bloghost.com and ns2.bloghost.com for any queries regarding blog.example.com.

Wildcard Subdomains

A wildcard subdomain is a catch-all subdomain that matches any subdomain that doesn’t have an explicitly defined DNS record. For instance, a wildcard DNS record like *.example.com would match any subdomain such as random.example.com, test.example.com, etc.

To create a wildcard record, add the following:

Name Type Value TTL
* A 192.0.2.100 3600

This would direct all undefined subdomains to the IP address 192.0.2.100.

Wildcard subdomains are useful for quickly adding a large number of subdomains without explicitly defining each one.

Common Subdomain Setup and DNS Issues

Subdomain Not Resolving

If your subdomain isn’t resolving, check the following:

  • DNS Record Propagation: DNS changes may take up to 48 hours to propagate across all servers. Use tools like DNSChecker to verify global propagation.
  • Incorrect DNS Records: Double-check the A, CNAME, and other relevant records to ensure they point to the correct IP addresses or domains.
  • DNS Cache: Flush your local DNS cache and check again. You can flush the cache with the following commands:
    • Windows: ipconfig /flushdns
    • MacOS: sudo killall -HUP mDNSResponder
    • Linux: sudo systemd-resolve --flush-caches

Subdomain Resolves to the Wrong IP

If the subdomain resolves to the wrong IP address:

  • Check the A Record: Ensure that the correct IP address is specified for the A record.
  • Check for CNAME Conflicts: If using CNAME, ensure that there’s no conflict with existing A records.
  • Propagation Delay: If you’ve recently changed the DNS record, wait for the TTL to expire and allow for proper DNS propagation.

Unable to Send Emails from Subdomain

If you’re using a subdomain for email (e.g., mail.example.com) and emails are not sending correctly:

  • MX Records: Ensure that your MX records are correctly configured for the subdomain and point to the correct mail server.
  • SPF/DKIM Records: If you’re using email

authentication (SPF/DKIM), ensure that the appropriate records are set for the subdomain.

  • DNS Propagation: MX records can sometimes take longer to propagate, so ensure that the changes have been fully propagated before troubleshooting further.

Best Practices for Subdomain Setup and DNS Configuration

  • Keep DNS Records Organized: Label subdomains and DNS records clearly to avoid confusion. For example, use web, api, and mail as common subdomain names for specific services.
  • Use Strong TTL Values: Set TTL values that balance performance and flexibility, using shorter TTLs for frequently updated subdomains and longer ones for stable subdomains.
  • Consider Security: Implement security measures such as DNSSEC (Domain Name System Security Extensions) for added protection against DNS spoofing and cache poisoning.
  • Monitor Subdomain Health: Regularly monitor the health and performance of your subdomains using DNS monitoring services like Pingdom or UptimeRobot.
  • Document DNS Changes: Keep a record of all changes made to DNS settings for troubleshooting and auditing purposes.

Subdomain Setup & DNS Configuration: Usage, Technical Issues, and FAQ

When managing subdomains and DNS configuration, there are numerous common challenges and considerations. This section will provide an overview of the usage field, explore technical issues, and offer a technical FAQ to help users troubleshoot and resolve common problems related to subdomains and DNS configuration.

Usage Field of Subdomains and DNS Configuration

Subdomains and DNS configuration are primarily used for:

  1. Website Structuring: Subdomains allow the organization of different services or sections of a website (e.g., blog.example.com, shop.example.com).
  2. Service Isolation: Subdomains can point to different web applications or servers for specific purposes, such as api.example.com or support.example.com.
  3. Geographical Distribution: Subdomains can be used to manage geographically-targeted content (e.g., us.example.com, eu.example.com).
  4. Testing and Development: Subdomains like dev.example.com or staging.example.com help manage testing environments separate from production environments.
  5. Email Services: Subdomains are used to configure custom email services (e.g., mail.example.com or email.example.com).
  6. Third-party Integrations: For external services like subdomains for payment processors, marketing tools, or social media integrations (e.g., shop.example.com for a third-party store).
  7. Security: Subdomains can be configured for security-related purposes, such as secure.example.com for secure transactions or login.example.com for user authentication.

Common Technical Issues with Subdomain Setup & DNS Configuration

Subdomain Not Resolving

Symptoms: The subdomain does not load, or it returns an error such as "Server Not Found" or "DNS Lookup Failed."

Possible Causes:

  • Incorrect DNS records (A, CNAME, or NS records).
  • DNS changes not fully propagated.
  • Missing or incorrect Name Server (NS) delegation for the subdomain.
  • Cached DNS records in your local machine or resolver.

Subdomain Resolves to the Wrong IP Address

Symptoms: The subdomain resolves to an incorrect IP address or leads to a different server.

Possible Causes:

  • Misconfigured A record for the subdomain.
  • Conflicting DNS records (e.g., both A and CNAME records exist for the same subdomain).
  • TTL values too high, causing old records to persist.

Subdomain's DNS Records Not Propagating

Symptoms: Newly added or updated DNS records for a subdomain aren't appearing on the internet.

Possible Causes:

  • DNS propagation delay (can take up to 48 hours for global propagation).
  • Incorrect DNS settings or missing records.
  • The TTL value may be too high, delaying propagation.
  • Issues with the authoritative DNS server.

Email Issues with Subdomains (e.g., Mail Server Not Working)

Symptoms: Emails sent to or from an email address on the subdomain (e.g., mail@example.com) aren’t delivered or are marked as spam.

Possible Causes:

  • Incorrect MX records or missing MX records for the subdomain.
  • Lack of SPF, DKIM, or DMARC records for the subdomain.
  • DNS records are not properly configured for mail routing.

DNSSEC Validation Failures

Symptoms: DNS queries for the subdomain fail because DNSSEC validation fails.

Possible Causes:

  • Incorrect or expired DNSSEC records (e.g., RRSIG or DNSKEY).
  • Missing DS record in the parent zone.
  • Misconfiguration of DNSSEC keys, such as a mismatch between KSK and ZSK.

CNAME Loop or Misconfiguration

Symptoms: A subdomain points to another domain or subdomain (CNAME), but results in a DNS loop or failure to resolve.

Possible Causes:

  • CNAME pointing to another CNAME instead of an A record.
  • CNAME and A record conflicts for the same subdomain.
  • Misconfigured or circular CNAME records.

Subdomain Redirection Issues

Symptoms: A subdomain (e.g., blog.example.com) redirects to an unintended page, or the page is unavailable.

Possible Causes:

  • Improper HTTP redirects set on the server.
  • Misconfigured DNS settings causing DNS queries to return incorrect destinations.
  • Conflicts with existing web server configurations (e.g., .htaccess or Nginx config issues).

Subdomain Delegation Problems

Symptoms: A subdomain points to a different DNS server, but the delegation is not working correctly.

Possible Causes:

  • Missing NS records for the subdomain.
  • Incorrect delegation of the subdomain at the parent zone.
  • DNS resolution issues at the parent DNS server.

Subdomain SSL/TLS Certificate Issues

Symptoms: Subdomains with SSL certificates (e.g., https://blog.example.com) show certificate errors, such as "This site’s security certificate is not trusted."

Possible Causes:

  • Missing or misconfigured SSL/TLS certificates for the subdomain.
  • Wildcard SSL certificates not matching the subdomain properly.
  • The certificate might not cover the subdomain in question.

Wildcard Subdomain Configuration Problems

Symptoms: A wildcard subdomain (*.example.com) doesn’t behave as expected, either not resolving at all or pointing to an unintended location.

Possible Causes:

  • Incorrect DNS wildcard configuration (e.g., a missing * A or CNAME record).
  • Conflicts between explicit subdomain records and the wildcard entry.
  • Wildcard DNS records not set to match every possible subdomain.

Subdomain Setup & DNS Configuration

Here are 10 common technical queries users might have regarding subdomain setup and DNS configuration:

How do I create a subdomain?

To create a subdomain, log into your DNS hosting provider’s dashboard and add a new DNS record:

  • If pointing to an IP address, create an A record.
  • If pointing to another domain, create a CNAME record.
  • Specify the subdomain name (e.g., blog) and set the destination (e.g., IP address or domain).

Example for blog.example.com:

  • A Record: blog -> 192.0.2.1.

Why isn’t my subdomain resolving?

If your subdomain isn't resolving, check:

  • DNS records for correctness.
  • Propagation time (DNS changes can take up to 48 hours to propagate globally).
  • Your DNS cache or local network cache.

Try using online tools like DNSstuff or MXToolbox to check DNS propagation.

Can a subdomain have a different DNS server?

Yes, you can delegate a subdomain to another DNS server by setting NS records for the subdomain. This is often used when a third-party provider manages a subdomain.

Example:

  • blog.example.com NS -> ns1.thirdparty.com.

How do I configure email for a subdomain?

To configure email for a subdomain, set up MX records for the subdomain in your DNS zone. Also, make sure to configure SPF, DKIM, and DMARC for email authentication.

Example for mail.example.com:

  • MX Record: mail -> mailserver.example.com.

What is the TTL for subdomain records?

TTL (Time to Live) specifies how long DNS records are cached. A shorter TTL (e.g., 300 seconds) can speed up propagation and help during troubleshooting, while a longer TTL (e.g., 86400 seconds) can reduce DNS lookup times.

How do I set up DNSSEC for a subdomain?

To set up DNSSEC for a subdomain:

  1. Generate the DNSSEC keys for your subdomain.
  2. Sign the zone with the keys.
  3. Add the DS record to the parent zone.
  4. Verify with DNSSEC validation tools.

Check your DNSSEC status using tools like DNSViz.

What causes a subdomain to redirect to the wrong site?

Redirect issues can occur due to:

  • Incorrect HTTP redirections set on the server (e.g., .htaccess or Nginx configurations).
  • Misconfigured DNS records.
  • Conflict between DNS settings and web server redirects.

Ensure that DNS settings and web server configurations are correctly aligned.

Can I use a wildcard subdomain for all subdomains?

Yes, a wildcard (*) DNS record can be set up to match any subdomain that doesn’t have an explicit record. For example:

  • Wildcard Record: * -> 192.0.2.100 (matches any subdomain, such as anything.example.com).

How do I test if a subdomain is working correctly?

You can test subdomain resolution with command-line tools like nslookup or dig, or use online tools like DNSstuff or Pingdom.

How do I fix a DNS CNAME loop?

A CNAME loop happens when a CNAME record points to another CNAME record, leading to a circular reference. To resolve:

  • Ensure CNAME records point to an A record (not another CNAME).
  • Check your DNS zone for circular references and remove any conflicting CNAME records.
  • 0 användare blev hjälpta av detta svar
Hjälpte svaret dig?