Dynamic DNS (dyndns) with Namecheap on Unifi Security Gateway Pro 4

In my last blog post I wrote about setting up WireGuard server on my USG. One thing that many of us home users have in common that we have dynamic ip addresses that change time to time. This can be troublesome when using the VPN as the IP can change any time and normally it happens when you would actually need the VPN working 🤪 Luckily this problem has been solved long time ago with dynamic DNS. The system works so that you have a daemon running in your server and when the ip address changes it updates the new ip address to the dynamic dns record. This makes it feel like you have a static ip address to which you have assigned a hostname.

I chose Namecheap for the service to run my dynamic DNS. I would have liked to use Cloudflare but there was no direct support for it in USG. Also all CLI setups seemed a little too complicated to have as a persistent setup. To be able to setup dynamic DNS via Namecheap you need to have a Namecheap account and a domain hosted with them. When you have these here are the steps that you can follow to get it working.

On the Namecheap side you need to do the following:

  1. Login to your Namecheap account
  2. Click manage on the domain you want to use
  3. Go to Advanced DNS
  4. Activate Dynamic DNS service and save the password for later use
  5. Add a A+Dynamic DNS Record type of record
  6. If you want to use naked domain use @ as the host. Otherwise use a subdomain of your choice.
  7. Add 127.0.0.1 as IP address. This will be replaced with a real IP address by the dyndns daemon.
  8. Remember to save changes by clicking the green save changes icon

On the USG contoller you need to do the following:

  1. Login to your USG contoller
  2. Navigate to Settings > Services > Dynamic DNS
  3. Press Create new dynamic DNS button
  4. Insert the following details
    1. Select the WAN interface that you are using
    2. Select namecheap from the Service list
    3. Add @ as the hostname or the subdomain you setup earlier in Namecheap
    4. Use your domain as the Username
    5. Use the Dynamic DNS service password that you saved earlier
    6. Use dynamicdns.park-your-domain.com as the Server
  5. Click save and you should be all setup!