Bulk Update Nameservers in cPanel/WHM Zone Editor with Reliability and Backups!
Author: Developed by Dhruval Joshi from HostingSpell.com. | Personal: TheDhruval.com
GitHub: @thekugelblitz
This script was created by me & optimized by ChatGPT 4 later.
A powerful, interactive, and production-safe script to bulk update NS (Nameserver) records across all DNS zones on a cPanel WHM server.
- 🔄 Dynamic NS Replacement – Supports any number of old and new NS entries.
- 🔍 Dry-Run Mode – Preview changes before applying them.
- ♻️ Rollback Mode – Restore all DNS zones from backup with one command.
- 📁 Centralized Backup – All zone files are backed up to a timestamped folder.
- 📊 Summary Report – Clear output of domains updated, skipped, or failed.
- 🧾 Log File – All actions logged to
/root/nsupdater.log
. - 🧠 Smart Exclusion – Automatically excludes the domain associated with your new NS.
- 🎨 Color-coded Output – Easy-to-read terminal feedback.
- Prompts for the number of old and new NS entries.
- Automatically excludes the domain associated with new NS (e.g.,
host3k.com
). - Backs up all DNS zone files before any change to a timestamped folder.
- Replaces old NS entries with new ones using
sed
. - Updates the DNS serial number to ensure propagation.
- Reloads DNS configuration only once after all changes.
- Logs all activity to
/root/nsupdater.log
. - It provides a final summary with counts and paths.
From https://github.com/thekugelblitz/nsupdater-cPanel-WHM
wget https://raw.githubusercontent.com/thekugelblitz/nsupdater-cPanel-WHM/main/nsupdater.sh -O nsupdater_v2.sh
chmod +x nsupdater_v2.sh
Then run the script using:
./nsupdater_v2.sh
Make the script executable:
chmod +x nsupdater_v2.sh
Run it as needed:
./nsupdater_v2.sh
./nsupdater_v2.sh --dry-run
./nsupdater_v2.sh --rollback
/root/
├── nsupdater_v2.sh # Main script
├── nsupdater.log # Action log
└── nsupdater_backup_YYYYMMDD_HHMM/ # Folder with backups
└── domain.com.db.bak
Enter the number of old NS entries: 2
Enter old NS entry 1: ns1.oldprovider.com.
Enter old NS entry 2: ns2.oldprovider.com.
Enter the number of new NS entries: 2
Enter new NS entry 1: ns1.host3k.com.
Enter new NS entry 2: ns2.host3k.com.
New NS domain will be excluded: host3k.com
Processing: clientdomain1.com
✔ Updated and serial bumped
Processing: clientdomain2.com
✔ Updated and serial bumped
──────────── Summary ─────────────
Total domains processed: 2
Updated successfully: 2
Skipped (dry-run or excluded): 0
Failed: 0
Backup location: /root/nsupdater_backup_20250328_1914/
Log file: /root/nsupdater.log
────────────────────────────────────
- Must be run as
root
- Assumes
.db
zone files exist in/var/named/
- Automatically creates the backup folder and log file
This script is released under the GNU GENERAL PUBLIC LICENSE Version 3. You are free to modify and use it for commercial or personal use. Attribution is appreciated! 😊
Developed by Dhruval Joshi from HostingSpell
GitHub Profile: @thekugelblitz