0
0
FirebaseHow-ToBeginner Ā· 4 min read

How to Use Custom Domain with Firebase Hosting

To use a custom domain with Firebase Hosting, add your domain in the Firebase Console under Hosting settings, then verify domain ownership by adding the provided DNS records at your domain registrar. Finally, Firebase will provision an SSL certificate and serve your site securely on your custom domain.
šŸ“

Syntax

Using a custom domain with Firebase Hosting involves these main steps:

  • Add Domain: Specify your custom domain in Firebase Console.
  • Verify Ownership: Add DNS TXT records to prove you own the domain.
  • Configure DNS: Add A and AAAA records to point your domain to Firebase Hosting servers.
  • SSL Setup: Firebase automatically provisions SSL certificates for secure HTTPS.
bash
firebase hosting:sites:add <your-site-id>
firebase hosting:channel:deploy live

# In Firebase Console:
# 1. Go to Hosting > Add custom domain
# 2. Enter your domain name
# 3. Follow DNS verification instructions

# Example DNS records:
# TXT record for verification: google-site-verification=xxxxxx
# A record for hosting:
# 199.36.158.100
# AAAA record for hosting:
# 2600:1901:0:xxxx::1
šŸ’»

Example

This example shows how to add and verify a custom domain example.com for your Firebase Hosting site.

bash
# Step 1: Deploy your site
firebase deploy --only hosting

# Step 2: In Firebase Console, add 'example.com' as custom domain
# Step 3: Firebase gives DNS TXT record:
# Name: @
# Type: TXT
# Value: google-site-verification=abc123xyz

# Step 4: Add DNS A record at your domain registrar:
# example.com A 199.36.158.100
# example.com AAAA 2600:1901:0:abcd::1

# Step 5: Wait for DNS propagation and Firebase SSL provisioning

# After setup, your site is live at https://example.com
Output
āœ” Deploy complete! āœ” Custom domain example.com added āœ” Domain ownership verified āœ” SSL certificate provisioned Your site is live at https://example.com
āš ļø

Common Pitfalls

Common mistakes when using custom domains with Firebase Hosting include:

  • Not adding the DNS TXT record correctly, causing verification failure.
  • Forgetting to add A and AAAA records, so the domain does not point to Firebase.
  • Trying to use subdomains without proper DNS setup.
  • Not waiting enough time for DNS changes to propagate before testing.

Always double-check DNS entries and use online DNS checkers to confirm.

bash
# Wrong: Missing TXT record for verification
# No TXT record added

# Right: Add TXT record
# example.com TXT google-site-verification=abc123xyz

# Wrong: Missing A/AAAA records
# No A or AAAA records

# Right: Add A and AAAA records
# example.com A 199.36.158.100
# example.com AAAA 2600:1901:0:abcd::1
šŸ“Š

Quick Reference

StepActionDetails
1Add DomainIn Firebase Console Hosting, enter your custom domain
2Verify OwnershipAdd DNS TXT record provided by Firebase
3Configure DNSAdd A and AAAA records pointing to Firebase IPs
4WaitAllow DNS propagation and SSL certificate provisioning
5TestVisit your domain with HTTPS to confirm setup
āœ…

Key Takeaways

Add your custom domain in Firebase Console under Hosting settings.
Verify domain ownership by adding the DNS TXT record exactly as provided.
Configure A and AAAA DNS records to point your domain to Firebase Hosting IPs.
Wait for DNS changes to propagate and Firebase to provision SSL certificates.
Test your site with HTTPS to ensure the custom domain works correctly.