How to add a custom domain to a Firebase hosting

Shehan Wijethunga
3 min readMar 7, 2021

--

We are going to add a custom domain to a Firebase hosting and add new records to Cloudflare DNS.

You’ll need

  • Hosting enabled firebase project
  • Cloudflare site (registered for the domain we are going to add)

1. Add new domain to firebase hosting

First, we should open our firebase project and navigate to the hosting page by using the menu. We can see the domains that already given by Google. Then click on “Add custom domain” to add our new domain.

Hosting page of a firebase project

We can type out new domain in the given text box as the following screenshot. We should add exampledomain.com without www. If we are adding a subdomain, the input should besubdomain.exampledomain.com. Then click on continue.

Enter domain tab — Add custom domain

2. Verify new domain

Now we can see the ownership verification tab that contains instructions to verify our new domain

Ownership verification tab — Add custom domain

Now we can add a new TXT record to our DNS. Here I’m using a Cloudflare site. But you can do the same steps with any DNS.

Click on “Add record” to add the given TXT record by firebase. Select TXT as the type. Enter the host in the name field. Here, it’s exampledomain.com. Copy and paste the value given by firebase into the content field as the above screenshot. Then click on save.

Now we should navigate back to our firebase project. Click on the Verify button on the verification ownership tab. If you have done the above steps correctly, you can see the 3rd step (Go live tab).

Go live tab — Add custom domain

3. Go live

This is the final step. Now we should create two A records in the DNS as given in the Go live tab.

Navigate to the DNS.

Click on “Add record”. Select A as the type, our new domain as the name. Here it’s exampledomain.com. But if you are adding a subdomain as subdomain.exampledomain.com, you should enter subdomain as the name. Then click on save.

When we add these two records, it looks like the following screenshot.

Finally, navigate back to firebase project and click on Finish. Now we can see our new domain in the firebase hosting page. After a few minutes, the new domain will be activated. That’s all.

Thank you for reading 🙏

--

--