5. Setting Up a Free Domain with DuckDNS
๐ฏ Goal
Set up a free subdomain using DuckDNS that points to your Azure VM, enabling you to use Let’s Encrypt SSL certificates and access your application with a memorable domain name instead of an IP address.
๐ Prerequisites
Before beginning this tutorial, you should:
- Have an Azure VM running with a static public IP address
- Know your VM’s public IP address
- Have an email address for account registration
- Understand basic DNS concepts (A records, domain resolution)
๐ Learning Objectives
By the end of this tutorial, you will:
- Understand DNS fundamentals and how domains work
- Create a free DuckDNS account and subdomain
- Configure DNS records to point to your Azure VM
- Verify domain resolution and connectivity
- Understand dynamic DNS concepts and automatic IP updates
- Learn how to manage and update your DuckDNS domain
๐ Why This Matters
Having a domain name for your application is important because:
- SSL certificates require domains - Let’s Encrypt cannot issue certificates for IP addresses
- Professional appearance - Users trust domains more than IP addresses
- Easier to remember -
myapp.duckdns.orgis easier than20.123.45.67 - Email and branding - Enables professional communication and branding
- Service integration - Many third-party services require domain names
- Development workflows - Consistent URLs across environments
๐ Why DuckDNS?
DuckDNS is recommended because:
- Completely free - No hidden costs or limitations
- Reliable service - Running since 2014 with excellent uptime
- Simple setup - Minimal configuration required
- Automatic updates - Can automatically update IP when it changes
- Let’s Encrypt compatible - Works perfectly with SSL certificates
- No ads or restrictions - Clean, professional service
- Community supported - Open source and community-driven
Step 1: Create a DuckDNS Account
Open your web browser and navigate to:
https://www.duckdns.orgClick on one of the sign-in options. DuckDNS supports multiple authentication methods:
- Google (recommended for most users)
- GitHub (good for developers)
For this tutorial, we’ll use Google authentication:
- Click the Google button
- Sign in with your Google account
- Grant DuckDNS permission to access your basic profile information
After successful authentication, you’ll be redirected to your DuckDNS dashboard.
๐ก Information
- No email verification needed - Authentication through existing services eliminates this step
- Privacy friendly - DuckDNS only needs basic profile info to identify your account
- Multiple sign-in methods - You can use different methods to access the same account
- Free forever - DuckDNS is funded by donations and has no premium tiers
Step 2: Create Your First Subdomain
On your DuckDNS dashboard, you’ll see a section titled “domains” with an input field.
Choose your subdomain name:
- Think of a unique name that represents your project
- Examples:
mycontactapp,learningstack,testproject,johnsapp - Must be lowercase, can include numbers and hyphens
- Cannot start or end with a hyphen
Enter your chosen subdomain name in the text field.
Click the “add domain” button.
If the domain is available, it will appear in your domains list as:
yourname.duckdns.orgIf the domain is already taken, try variations:
- Add numbers:
myapp2024 - Add location:
myapp-europe - Add purpose:
myapp-demo
- Add numbers:
๐ก Information
- Subdomain format: All DuckDNS domains end with
.duckdns.org- Immediate availability: Domain is active as soon as you create it
- Free limits: You can create up to 4 subdomains per account
- No expiration: Domains remain active as long as you update them occasionally
โ ๏ธ Naming Best Practices
- Choose a name you’ll remember and can easily type
- Avoid special characters except hyphens
- Keep it short but descriptive
- Consider that this will be in your SSL certificate
Step 3: Configure DNS to Point to Your VM
Find your VM’s public IP address:
- In Azure Portal: Go to your VM โ Overview โ Public IP address
- Or via command line:
curl ifconfig.me(from your VM) - Or from your deployment script output
Back in your DuckDNS dashboard, locate your newly created domain.
In the “current ip” field next to your domain, enter your VM’s public IP address.
Click the “update ip” button next to your domain.
You should see a confirmation message, and the IP field should now show your VM’s IP address.
Note your token (displayed at the top of the page) - you’ll need this for automatic updates.
๐ก Information
- A Record: DuckDNS automatically creates an A record pointing your domain to the IP
- Immediate updates: DNS changes typically propagate within minutes
- Global propagation: Full global DNS propagation can take up to 24 hours
- Token security: Keep your token private - it allows anyone to update your domains
Step 4: Test Domain Resolution
Wait 2-3 minutes for DNS propagation to begin.
Test domain resolution from your local computer:
# On Windows (Command Prompt or PowerShell) nslookup yourname.duckdns.org # On macOS/Linux (Terminal) dig yourname.duckdns.org # or nslookup yourname.duckdns.orgYou should see output similar to:
Server: 8.8.8.8 Address: 8.8.8.8#53 Non-authoritative answer: Name: yourname.duckdns.org Address: YOUR_VM_IP_ADDRESSTest HTTP connectivity:
curl -I http://yourname.duckdns.orgYou should receive a response from your Nginx server.
Test in your browser:
- Navigate to
http://yourname.duckdns.org - You should see your contact application
- The address bar should show your domain name instead of the IP
- Navigate to
โ Verification Steps
- DNS lookup returns your VM’s IP address
- HTTP request to domain name reaches your application
- Browser displays your application when accessing the domain
- phpMyAdmin accessible at
http://yourname.duckdns.org/phpmyadmin
Step 5: Set Up Automatic IP Updates (Optional)
If your VM has a dynamic IP or you want to ensure automatic updates, you can set up automatic IP updating.
Method 1: Manual Update URL
DuckDNS provides a simple update URL that you can call to update your IP.
The update URL format is:
https://www.duckdns.org/update?domains=yourname&token=YOUR_TOKEN&ip=Test the update URL:
curl "https://www.duckdns.org/update?domains=yourname&token=YOUR_TOKEN&ip="You should receive “OK” as a response.
Method 2: Automated Script (For Dynamic IPs)
If you have a dynamic IP that might change, create an update script:
sudo nano /usr/local/bin/duckdns-update.shAdd the script content:
#!/bin/bash # DuckDNS IP Update Script DOMAIN="yourname" # Replace with your domain name (without .duckdns.org) TOKEN="YOUR_TOKEN" # Replace with your actual token # Get current public IP CURRENT_IP=$(curl -s ifconfig.me) # Update DuckDNS RESPONSE=$(curl -s "https://www.duckdns.org/update?domains=$DOMAIN&token=$TOKEN&ip=$CURRENT_IP") # Log the update echo "$(date): Updated $DOMAIN.duckdns.org to $CURRENT_IP - Response: $RESPONSE" >> /var/log/duckdns.log if [ "$RESPONSE" = "OK" ]; then echo "DuckDNS update successful" else echo "DuckDNS update failed: $RESPONSE" fiMake the script executable:
sudo chmod +x /usr/local/bin/duckdns-update.shTest the script:
sudo /usr/local/bin/duckdns-update.shSet up a cron job to run the update script regularly:
sudo crontab -eAdd a line to update every 5 minutes:
# Update DuckDNS IP every 5 minutes */5 * * * * /usr/local/bin/duckdns-update.sh
๐ก Information
- For static IPs: Automatic updates are not necessary
- For dynamic IPs: Regular updates ensure your domain always points to current IP
- Update frequency: Every 5 minutes is sufficient for most use cases
- Log monitoring: Check
/var/log/duckdns.logto verify updates are working
Step 6: Prepare for SSL Certificate Setup
Now that you have a working domain, you’re ready to use it with Let’s Encrypt SSL certificates.
Update your Nginx configuration to use your domain name:
sudo nano /etc/nginx/sites-available/defaultReplace server_name with your domain:
server { listen 80; server_name yourname.duckdns.org; # Replace with your actual domain # ... rest of configuration }Test and reload Nginx:
sudo nginx -t sudo systemctl reload nginxVerify domain access before proceeding to SSL setup:
- Ensure
http://yourname.duckdns.orgloads your application - Ensure
http://yourname.duckdns.org/phpmyadminloads phpMyAdmin
- Ensure
๐ฏ Ready for SSL!
Your domain is now properly configured and ready for Let’s Encrypt SSL certificate installation. You can proceed with Tutorial 4: SSL Configuration - Part 2 (Let’s Encrypt).
๐งช Final Tests
Test 1: DNS Resolution
From multiple locations/devices, test DNS resolution:
nslookup yourname.duckdns.orgShould consistently return your VM’s IP address.
Test 2: HTTP Connectivity
Test HTTP access from different networks:
curl -I http://yourname.duckdns.orgShould receive proper HTTP response headers.
Test 3: Application Functionality
- Access your contact form at
http://yourname.duckdns.org - Submit a test message
- Verify the form works correctly with the domain name
- Access phpMyAdmin at
http://yourname.duckdns.org/phpmyadmin
โ Expected Results
- Domain consistently resolves to your VM’s IP address
- HTTP requests to domain reach your application correctly
- All application features work with domain name instead of IP
- Ready to proceed with Let’s Encrypt SSL certificate installation
๐ง Troubleshooting
Domain doesn’t resolve
If DNS lookup fails:
- Wait longer for DNS propagation (up to 24 hours globally)
- Try different DNS servers:
nslookup yourname.duckdns.org 8.8.8.8 - Verify IP address is correctly set in DuckDNS dashboard
- Check for typos in domain name
Domain resolves but HTTP fails
If DNS works but HTTP connection fails:
- Verify your VM is running:
sudo systemctl status nginx - Check firewall allows HTTP:
sudo ufw status - Ensure Nginx is configured for your domain name
- Test direct IP access to isolate the issue
Automatic updates not working
If the update script fails:
- Check token is correct in the script
- Verify domain name (without .duckdns.org) in script
- Test manual curl command first
- Check script permissions:
ls -la /usr/local/bin/duckdns-update.sh - Review cron logs:
sudo tail -f /var/log/duckdns.log
๐ Optional Challenge
Want to enhance your domain setup further? Try:
- Setting up multiple subdomains for different services
- Creating a monitoring script to alert if domain resolution fails
- Implementing backup DNS providers for redundancy
- Setting up custom 404 pages for your domain
- Configuring email forwarding if your DNS provider supports it
๐ Further Reading
- DuckDNS Documentation - Official DuckDNS API documentation
- DNS Basics - Cloudflare Learning - Understanding how DNS works
- Let’s Encrypt Domain Validation - How Let’s Encrypt validates domain ownership
- Dynamic DNS Concepts - Understanding dynamic DNS services
Done! ๐
Excellent work! You’ve successfully set up a free domain with DuckDNS that points to your Azure VM. Your application is now accessible via a memorable domain name and ready for SSL certificate installation. You can now proceed with Let’s Encrypt SSL configuration using your new domain! ๐