Opening up Home Assistant to the internet with Duck DNS
Disclosure: This post contains affiliate links. If you click through and make a purchase, I will earn a commission, at no additional cost to you. Read my full disclosure here.
For those with privacy concerns, the following steps may not be suitable. This guide will demonstrate how to open your Home Assistant to the internet, exposing it to potential risks. It is essential to set a strong password for your Home Assistant account before proceeding.
In the following paragraphs, I will show you how to set up a custom URL using Duck DNS, and how to encrypt it using Let's Encrypt. Additionally, we will explain which ports need to be opened on your router to complete the setup.
The great thing about using Duck DNS with Home Assistant is that you don't need to worry about owning a static IP or the correct certificates. The Home Assistant add-on takes care of everything: It will update your Duck DNS subdomain with your current public IP, and it will make sure that the free Let's Encrypt certificates are always valid.
Configuring Home Assistant to use a static IP
It is imperative to configure Home Assistant to use a static IP before anything else. There are a few ways of doing this, but the easiest is built right into the Home Assistant settings. Open the Home Assistant Dashboard and navigate to the Settings, next select System, and finally Network. In the card titled 'Configure network interfaces' you should see your wired and wireless network interfaces.
If you have followed my recommendations, you will be using a wired connection, and thus will be using ETH0. Simply switch from DHCP to Static and Home Assistant will automatically insert the current configuration it has received from the DHCP. If, for some reason, the information is not automatically entered, I have described how to figure out your gateway and IP address in a previous guide.
The reason behind doing this is that we will need to configure port forwarding in a later step. If the DHCP lease is up, and your Raspberry Pi running Home Assistant is assigned a new IP address, the port forwarding will no longer work.
Signing up for a Duck DNS account
Signing up for a Duck DNS account only requires you logging in using a Twitter, Google, or Google account. Once logged in, you can register your subdomain using the prominent text field. The only other information you will need from this site is your token, As with all tokens and password, you should never share this one with anyone.
Installing and configuring the Duck DNS add-on for Home Assistant
I've covered the installation of Home Assistant add-ons in a previous guide. If you are unsure on how to proceed, refresh your memory by reading that article. The Duck DNS add-on is found as part of the official add-ons. Simply select and install it to get started.
Once installed, there is no need to immediately start the Duck DNS add-on, as it won't be able to function without having been set up first.
Select the Configuration tab and enter your domain name and token, which you previously copied from Duck DNS. You will also have to change one line in the text field for Let's Encrypt: Instead of accept_terms: false, you will want to change it to accept_terms: true. As mentioned earlier, the free SSL certificate is provided by Let's Encrypt, making sure your connection is safe and secure. If interested, you can read up on the terms of service on their website. Once done, you will need to click on the button titled 'save' to continue.
You can now return to the Info tab, and finally start the Duck DNS add-on. However, before you start it, you can also decide whether you want to enable the watchdog and auto-updates.
Configuring Home Assistant's internal and external URL
After having configured the Duck DNS add-on, you will need to define Home Assistant's external/internet and internal/local URL. This is done so that you can access the Home Assistant Dashboard locally when at home, and using the URL when you are out. Head back to the same place where you configured the static IP address, and enter the appropriate URLs.
Letting Home Assistant know where the SSL certificates are
The last piece of information Home Assistant needs to be aware of is the location of the SSL certificates. To accomplish this, you can use the Studio Code Server add-on to open up the configuration.yaml file. Towards the bottom of this file, you simply need to add the following code:
The last piece of information Home Assistant needs to be aware of is the location of the SSL certificates. To accomplish this, you can use the Studio Code Server add-on to open up the configuration.yaml file. Towards the bottom of this file, you simply need to add the following code: