← Back to Bootcamp

Lesson 2: Domain, DNS & Dynamic IP

Connect your server to a real domain name and keep it reachable even when your ISP changes your IP

Prep
Apache
Files
Firewall
Network
Router
DNS
HTTPS
Progress: 0/4 steps completed
1
Understand the Problem
Why your public IP is not enough

What is Dynamic IP?

Most home internet plans assign a dynamic IP address — it changes periodically (daily, weekly, or when your router reboots). If someone bookmarks your site at 203.0.113.45, that address might be dead tomorrow.

What is DNS?

Domain Name System is the phonebook of the internet. It translates human-readable names like google.com into IP addresses like 142.250.80.46. Without DNS, we would all be typing numbers.

What is Dynamic DNS?

A service that gives you a free domain name and automatically updates the IP address record whenever your home IP changes. You get a stable name like yourname.duckdns.org that always points to your current IP.

2
Get Your Public IP
The address the internet sees

Two different addresses

You have a local IP (like 192.168.88.8) that only works inside your house. Your router has a public IP that the entire internet sees. When someone visits your site from another city, they use your public IP.

Get your public IP

curl ifconfig.me
  • This asks an external service to tell you what IP address it sees from your connection
  • It will look different from your local IP — something like 203.0.113.45
  • Write this number down.
3
Set Up DuckDNS
Free domain name that follows your IP

Why DuckDNS?

It is free, simple, and designed specifically for home servers. No credit card. No expiration. Just a subdomain and a token.

Step 3A: Sign up

  • Go to duckdns.org
  • Sign in with Google, GitHub, or Reddit
  • Create a subdomain: yourname.duckdns.org
  • Copy your token (a long string of letters and numbers)

Step 3B: Create the update script on your server

mkdir ~/duckdns && cd ~/duckdns
nano duck.sh

Type this inside nano (replace YOURNAME and YOUR_TOKEN):

echo url="https://www.duckdns.org/update?domains=YOURNAME&token=YOUR_TOKEN&ip=" | curl -k -o ~/duckdns/duck.log -K -
  • Press Ctrl+O, then Enter, then Ctrl+X

Step 3C: Make it executable and test

chmod 700 duck.sh ./duck.sh cat duck.log
  • chmod 700 makes the script runnable by only you
  • ./duck.sh runs it
  • cat duck.log shows the result — it should say OK
4
Automate the Update
Keep your domain pointing to your IP forever

What is cron?

cron is Linux's built-in scheduler. It runs commands automatically at intervals you define. We will tell it to run your DuckDNS script every 5 minutes.

Edit your crontab

crontab -e
  • If it asks which editor to use, choose nano (option 1)
  • Add this line at the bottom:
*/5 * * * * ~/duckdns/duck.sh >/dev/null 2>&1
  • This means: "Run the script every 5 minutes, silently."
  • Press Ctrl+O, Enter, Ctrl+X

Verify it is working

crontab -l
  • This lists your scheduled jobs. You should see the DuckDNS line.

Test your domain

Wait 2–3 minutes, then visit:

http://yourname.duckdns.org

Replace with your actual DuckDNS subdomain.

⚠️ It doesn't work?

  • Check port forwarding — Your router must forward port 80 to your server's local IP (Lesson 1, Step 6).
  • Check the logcat ~/duckdns/duck.log should say OK.
  • Check your token — Make sure you copied it exactly from duckdns.org.