Skip to content

Instantly share code, notes, and snippets.

@dallin
Last active August 13, 2021 18:59
Show Gist options
  • Save dallin/b64e3bbbb228e82f2c5287d7461ca510 to your computer and use it in GitHub Desktop.
Save dallin/b64e3bbbb228e82f2c5287d7461ca510 to your computer and use it in GitHub Desktop.
UniFi USG Dynamic DNS with Namecheap (behind NAT)

UniFi USG Dynamic DNS with Namecheap (behind NAT)

This is useful if...

  1. Your USG sits behind another firewall (such as in an apartment complex or dorm)
  2. Your USG receives a private IP instead of a public one
  3. You are unable to put the other router in bridge mode or passthrough mode
  4. The other router forwards all ports for the public IP to your USG

Instructions

  1. Enable Dynamic DNS for your domain in Namecheap
  2. Create an A+Dynamic DNS record for the desired hostname
  3. Edit the values in this script (make sure to remove the brackets as well...)
    • host: The hostname you created in step 2
    • domain_name: The domain that you are updating in Namecheap
    • ddns_password: The Dynamic DNS Password shown in the Dynamic DNS section on the Advanced DNS page in Namecheap
  4. SSH into the USG
  5. Become root (run sudo su)
  6. Run this script (you can also just copy/paste lines 2-6 into the terminal)
  7. ????
  8. PROFIT!!!
#!/bin/bash
cat << 'EOF' > /etc/cron.hourly/ddns-namecheap
IP=$(curl -4 -s -L ifconfig.co)
curl -s -L "https://dynamicdns.park-your-domain.com/update?host=[host]&domain=[domain_name]&password=[ddns_password]&ip=$IP"
EOF
chmod +x /etc/cron.hourly/ddns-namecheap
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment