Configure Dynamic DNS in Namecheap with Bash and Cron

by Fahim Mahmud Chisti

To configure Dynamic DNS in Namecheap, turn on Dynamic DNS for the domain and create an A + Dynamic DNS Record for your host. A small Bash script on a cron schedule then sends your current public IP to Namecheap whenever it changes. Your home or lab server then stays reachable at a name like dev.example.com, even when your ISP hands you a new IP address.

Quick answer: Namecheap updates a dynamic host when you call its update URL with the host, domain, Dynamic DNS password and IP. A cron job can make that call for you.

  1. In Namecheap Advanced DNS, enable Dynamic DNS and copy the Dynamic DNS password.
  2. Add an A + Dynamic DNS Record for your host, such as dev.
  3. Test the update URL once with curl and look for <ErrCount>0</ErrCount>.
  4. Install the Bash script, which only contacts Namecheap when your IP changes.
  5. Run it from root’s crontab every 10 minutes.
In this guide
  1. Before You Start
  2. How Namecheap Dynamic DNS Works
  3. Step 1: Enable Dynamic DNS in Namecheap
  4. Step 2: Add the Dynamic Host Record
  5. Step 3: Test the Update URL with curl
  6. Step 4: Install the Update Script
  7. Step 5: Run the Script and Verify the Record
  8. Step 6: Schedule the Script with Cron
  9. Step 7: Rotate the Log File
  10. If It Still Doesn’t Work
  11. Frequently Asked Questions
  12. Next Steps
Mini dev server on a shelf with Ethernet connection showing dynamic DNS automation setup

Before You Start

  • DNS host: Namecheap Dynamic DNS only works on domains that use BasicDNS, PremiumDNS or FreeDNS. Run dig +short NS example.com; on BasicDNS it prints dns1.registrar-servers.com. and dns2.registrar-servers.com.
  • Access: your Namecheap login and a Linux machine (Debian, Ubuntu or Alpine) on the network whose IP you want to publish, with sudo rights.
  • Packages: bash and curl. Debian and Ubuntu usually have both; on Alpine, run apk add bash curl first.
  • Time: about 15 minutes.
  • Use a dedicated host name: put the dynamic record on a subdomain such as dev or lab, not on @, unless the whole domain really runs from that machine. A bad update then cannot take your main site offline.
  • Reachability: Dynamic DNS only publishes your IP. To reach the machine from outside, you still need port forwarding on your router. It also will not work if your ISP puts you behind CGNAT (carrier-grade NAT, where many customers share one public IP).

How Namecheap Dynamic DNS Works

Namecheap’s dynamic DNS needs no API key or OAuth setup. Each domain gets its own Dynamic DNS password, and a single HTTPS GET request with that password updates the record.

The request carries your domain, the host (subdomain or root), the password and the IP to publish. Namecheap updates the A + Dynamic DNS record on its nameservers and replies with a short XML message saying whether it worked. If you already know how to point a root domain in Namecheap DNS using an A record, this simply automates changing that record’s IP whenever your ISP changes it.

Step 1: Enable Dynamic DNS in Namecheap

Turn the feature on and copy the password the script will use:

  1. Log into Namecheap and go to your Domain List.
  2. Click Manage next to your domain.
  3. Head over to the Advanced DNS tab.
  4. Scroll down to Dynamic DNS and toggle it to Enabled.
  5. Copy the alphanumeric string under Dynamic DNS Password and drop it into your password manager.

Step 2: Add the Dynamic Host Record

On the same page, go to the Host Records table and add a record for the host you want to update:

Type Host Value TTL
A + Dynamic DNS Record dev (or lab, or @ for the root) 127.0.0.1 (temporary placeholder) 1 min or 5 min

The placeholder is replaced on the first successful update. A short TTL matters here: with Automatic, resolvers can keep serving your old IP for up to 30 minutes after a change. If you run several machines on different subdomains, see how to route subdomains to different servers in Namecheap DNS.

Step 3: Test the Update URL with curl

The update endpoint takes four query parameters over HTTPS. Test it once by hand with curl before you automate anything, so you know the password and host are right.

Run this in a terminal on the server, with your own domain, host, password and current public IP:

curl -s "https://dynamicdns.park-your-domain.com/update?host=dev&domain=example.com&password=YOUR_DDNS_PASSWORD&ip=203.0.113.42"

Namecheap replies with XML. Look for the <ErrCount> tag: 0 means success. If you see 1, the <Err1> element spells out the problem (usually a mistyped password or a host record that doesn’t exist yet).

Step 4: Install the Update Script

Calling Namecheap on every run is wasteful. The script below saves the last known IP in /var/tmp/namecheap_ddns_last_ip.txt and only sends an update when your IP has actually changed.

On the server, create a folder for the script and open a new file:

sudo mkdir -p /opt/scripts
sudo nano /opt/scripts/namecheap-ddns.sh

Paste the following into /opt/scripts/namecheap-ddns.sh, then replace DOMAIN, HOST and PASSWORD with your values:

#!/usr/bin/env bash
set -euo pipefail

# Configuration
DOMAIN="example.com"
HOST="dev"
PASSWORD="YOUR_NAMECHEAP_DDNS_PASSWORD"
IP_CACHE_FILE="/var/tmp/namecheap_ddns_last_ip.txt"
LOG_FILE="/var/log/namecheap-ddns.log"

log() {
    echo "$(date '+%Y-%m-%d %H:%M:%S') $1" >> "$LOG_FILE"
}

# Fetch current public IPv4 address (-4 forces IPv4 on dual-stack networks)
CURRENT_IP=$(curl -4 -s --max-time 10 https://api.ipify.org || curl -4 -s --max-time 10 https://icanhazip.com || true)
CURRENT_IP=$(echo "$CURRENT_IP" | tr -d '[:space:]')

# Sanity check: make sure we got something that looks like an IPv4 address
if [[ ! "$CURRENT_IP" =~ ^[0-9]{1,3}(\.[0-9]{1,3}){3}$ ]]; then
    log "[ERROR] Failed to obtain a valid public IP. Got: '$CURRENT_IP'"
    exit 1
fi

# Check against cached IP
LAST_IP=""
if [[ -f "$IP_CACHE_FILE" ]]; then
    LAST_IP=$(cat "$IP_CACHE_FILE")
fi

if [[ "$CURRENT_IP" == "$LAST_IP" ]]; then
    # IP has not changed; exit cleanly without calling Namecheap
    exit 0
fi

# Send update request to Namecheap
RESPONSE=$(curl -s --max-time 15 "https://dynamicdns.park-your-domain.com/update?host=${HOST}&domain=${DOMAIN}&password=${PASSWORD}&ip=${CURRENT_IP}" || true)

# Validate response
if echo "$RESPONSE" | grep -q "<ErrCount>0</ErrCount>"; then
    echo "$CURRENT_IP" > "$IP_CACHE_FILE"
    log "[SUCCESS] IP updated from '${LAST_IP}' to '${CURRENT_IP}' for ${HOST}.${DOMAIN}"
else
    ERR_MSG=$(echo "$RESPONSE" | grep -o '<Err1>.*</Err1>' || echo "Unknown error")
    log "[ERROR] Namecheap DDNS update failed: ${ERR_MSG}"
    exit 1
fi

In short: the script asks two public services for your IPv4 address, checks that the answer looks like an IP, compares it with the saved one, and calls Namecheap only if it changed. Every update and every error goes to /var/log/namecheap-ddns.log.

Lock down the file so other users on the machine cannot read your Dynamic DNS password:

sudo chmod 700 /opt/scripts/namecheap-ddns.sh
sudo chown root:root /opt/scripts/namecheap-ddns.sh

These commands print nothing when they succeed. On a machine shared with other people, note that the password also appears briefly in the process list while curl runs.

Step 5: Run the Script and Verify the Record

Run the script once by hand. This creates the cache file and confirms your settings work:

sudo /opt/scripts/namecheap-ddns.sh

Then read the log file:

cat /var/log/namecheap-ddns.log

You should see one line like this, with your own IP and host:

2026-09-13 14:22:01 [SUCCESS] IP updated from '' to '198.51.100.23' for dev.example.com

Now ask Namecheap’s nameserver directly with dig, which skips your ISP’s cache:

dig @dns1.registrar-servers.com dev.example.com +short

It should print your current public IP right away. Public resolvers such as 8.8.8.8 follow within the TTL you chose in Step 2.

Step 6: Schedule the Script with Cron

A 10-minute schedule keeps any outage short without hammering the IP lookup services. Open root’s crontab (the script needs root to write its log file):

sudo crontab -e

Add this line at the bottom:

*/10 * * * * /opt/scripts/namecheap-ddns.sh > /dev/null 2>&1

Save and exit. Cron picks up the change immediately; no service restart is needed. To confirm it runs, check the log again after your next IP change, or delete the cache file and wait 10 minutes for a fresh [SUCCESS] line.

Step 7: Rotate the Log File

The log only grows when your IP changes or an error occurs, but over months it still adds up. A logrotate rule keeps it small.

Create the config file:

sudo nano /etc/logrotate.d/namecheap-ddns

Paste this in:

/var/log/namecheap-ddns.log {
    monthly
    rotate 4
    missingok
    notifempty
    compress
    delaycompress
    create 0600 root root
}

Do a dry run to check the syntax. It prints what logrotate would do without changing any files:

sudo logrotate -d /etc/logrotate.d/namecheap-ddns

If It Still Doesn’t Work

  • The log shows a Namecheap error: the <Err1> text is in the log line. Most often the password is wrong (it must be the Dynamic DNS password, not your account password) or the host in the script does not match a record in Host Records.
  • An IPv6 address was detected: on dual-stack networks, lookup services can return IPv6. Namecheap’s dynamic update only sets IPv4 A records, so the script passes -4 to both curl lookups to force IPv4.
  • It works by hand but not from cron: cron runs with a minimal PATH that can miss /usr/local/bin. The script’s #!/usr/bin/env bash line and standard tool paths avoid this; if you installed curl somewhere unusual, use its full path.
  • The record stopped updating after you edited it in Namecheap: the cache file still holds the old IP, so the script thinks nothing changed. Run sudo rm /var/tmp/namecheap_ddns_last_ip.txt and run the script again.
  • dig shows the right IP but you cannot connect: DNS is fine; the traffic is blocked. Check port forwarding on your router and the server’s firewall. Behind CGNAT, inbound connections cannot reach you at all; a tunnel works instead, as shown in our guide to test webhooks locally with Cloudflare Tunnels.

In the update URL, host=@ updates the root domain (example.com) and host=* updates a wildcard record.

Frequently Asked Questions

Can I update multiple subdomains with a single API request?

No. Namecheap needs one HTTP GET request per host. To update both dev.example.com and api.example.com, loop over a list of hosts in the script and send one request for each, keeping a separate cache file per host.

What is the minimum TTL for Namecheap Dynamic DNS records?

The record uses the TTL you pick for it in Advanced DNS, and the lowest option is 1 min. With Automatic (30 minutes), resolvers can keep serving the old IP for up to half an hour after an update, so choose 1 min or 5 min for a dynamic host.

Will enabling Dynamic DNS interfere with my CNAME or MX records?

No. Dynamic DNS only changes records whose type is A + Dynamic DNS Record, and only the one host you name in each request. Your MX, TXT and static CNAME records stay exactly as they are.

Why does Namecheap reject my password when it is correct?

You are most likely using your Namecheap account password. The Dynamic DNS password is a separate alphanumeric token shown in the Dynamic DNS section of the Advanced DNS tab. Copy it from there into the script’s PASSWORD line.

Next Steps

With the hostname following your IP, put a web server in front of your app and give it a certificate. Our guide to point a Namecheap subdomain to a separate server with Nginx covers the server block and SSL. Afterwards, check the log now and then to confirm updates keep succeeding.

all_in_one_marketing_tool