CodeWithAbdessamad

Connecting A Domain

Connecting a Domain

When you want your website to be accessible via a domain name (like myvps.example.com), you need to connect it to your VPS hosting. This section covers the essential steps to configure your domain’s DNS settings so it resolves to your VPS’s public IP address. We’ll focus on two critical components: DNS Configuration (the foundational setup) and A Records (the specific DNS records that link your domain to your VPS).

DNS Configuration

Before creating A records, you must configure your DNS provider. DNS (Domain Name System) acts as the internet’s “phone book,” translating human-readable domain names into IP addresses your VPS can use. Here’s how to set up your DNS provider:

  1. Log in to your DNS provider’s dashboard (e.g., Cloudflare, GoDaddy, Namecheap).
  2. Locate your domain’s DNS settings (typically under “Domains” or “DNS Management”).
  3. Verify domain ownership (if required) by adding a DNS record like a TXT record.

Example workflows:

  • Cloudflare:

Go to Cloudflare dashboard → “My Account” → “Domains” → Select your domain → Click “DNS” in the left sidebar.

  • GoDaddy:

Log in to GoDaddy → “Domains” → “Domain Settings” → “DNS”.

This setup ensures your domain is properly linked to your DNS provider—essential before adding A records.

A Records

Now that your DNS provider is configured, create an A record to map your domain to your VPS’s public IP address. An A record is a DNS record that resolves a domain name to an IPv4 address (e.g., 192.0.2.1).

Sample A record configuration:

Type Name Value TTL
A myvps.example.com 192.0.2.1 300

Step-by-step creation (using Cloudflare as an example):

  1. Go to Cloudflare dashboard → “Domains” → Select your domain → “DNS”.
  2. Click “Add Record”.
  3. Set Type = A.
  4. Enter Name = myvps.example.com.
  5. Enter Value = 192.0.2.1 (your VPS’s public IPv4 address).
  6. Set TTL = 300 (5 minutes; sufficient for most setups).
  7. Click “Add Record”.

Your domain now points to your VPS! 🌐

Critical notes:

  • Multiple A records: Add records for subdomains (e.g., www.myvps.example.com).
  • IPv6 support: If your VPS has IPv6, create a separate AAAA record (for IPv6 addresses).
  • Propagation: DNS changes take 1–24 hours to propagate globally (usually minutes). Test with:
<code class="language-bash">  # On your local machine (or any machine with internet access)</p>
<p>  dig +short myvps.example.com</code>

If the output is 192.0.2.1, your A record is working!

Summary

This section covers the critical steps to connect your domain to your VPS hosting. By configuring your DNS provider and creating an A record, you’ve established the foundation for your domain to resolve to your VPS’s public IP address. This is the essential first step before deploying Docker containers or web applications. Once your domain points to your VPS, the next step in our book (Chapter 4) will be setting up SSL to secure your connections. 🌟