DNS Cluster Setup Script
This shell script enables DNS clustering and configures two specific, write-only DNS servers.
Script Content (setup_dns_cluster.sh):
#!/bin/bash
# This script enables DNS clustering and adds two pre-configured servers.
# It will pause between steps, waiting for user input or a 10-second timeout.
# Exit immediately if a command exits with a non-zero status.
set -e
# --- Function to pause and wait for user input or a timeout ---
function continue_prompt() {
echo "" # Add a newline for better formatting.
# We run the prompt in a subshell (...) to localize the effect of 'set +e'.
# This prevents 'read -t' from triggering 'set -e' in the main script on timeout.
(
set +e # Disable 'exit on error' for this subshell only.
for i in $(seq 10 -1 1); do
read -s -n 1 -t 1 -p $'\rPress any key to continue, or auto-continuing in '"$i"' seconds... '
# Check the exit status of read. 0 means input was received.
if [ $? -eq 0 ]; then
echo -e "\r "
echo -e "\rKey pressed. Continuing..."
echo ""
exit 0 # Exit the subshell successfully.
fi
done
# This code is reached only if the loop completes without user input.
echo -e "\r "
echo -e "\rTimeout reached. Continuing automatically..."
echo ""
exit 0 # Exit the subshell successfully.
)
}
echo "--- Step 1: Enabling DNS Clustering ---"
whmapi1 set_tweaksetting key=dnsclustering value=1
echo "DNS Clustering has been enabled."
continue_prompt
echo "--- Step 2: Configure First DNS Cluster Server (Write-Only) ---"
# Hardcoded details for the first DNS server
# replace with your details
DNS_HOST1="ns00.hashdns.net"
DNS_USER1="root"
# replace with your details
DNS_KEY1="XXOO"
echo "Adding $DNS_HOST1 to the cluster as write-only..."
whmapi1 add_dns_cluster_member host="$DNS_HOST1" username="$DNS_USER1" key="$(echo -n "$DNS_KEY1" | tr -d '[:space:]')" dnsrole='writeonly'
echo "First DNS cluster member configured."
continue_prompt
echo "--- Step 3: Configure Second DNS Cluster Server (Write-Only) ---"
# Hardcoded details for the second DNS server
DNS_HOST2="ns00.hashdns.net"
DNS_USER2="root"
# replace with your details
DNS_KEY2="XXOO"
echo "Adding $DNS_HOST2 to the cluster as write-only..."
whmapi1 add_dns_cluster_member host="$DNS_HOST2" username="$DNS_USER2" key="$(echo -n "$DNS_KEY2" | tr -d '[:space:]')" dnsrole='writeonly'
echo "Second DNS cluster member configured."
echo ""
echo "--- DNS Cluster setup script finished. ---"
How to Use the Script
Follow these instructions to save and execute the script on your Linux server.
-
Connect to Your Server:
-
Use SSH to log into your server's command line.
-
-
Create the Script File:
-
Use a command-line text editor like
nanoto create a new file:nano setup_dns_cluster.sh
-
-
Add the Script Content:
-
Copy and paste the entire script content into the editor.
-
-
Save and Exit the File:
-
Press
CTRL + X, thenY, thenEnter.
-
-
Make the Script Executable:
-
Run this command:
chmod +x setup_dns_cluster.sh
-
-
Run the Script:
-
Run the script with
sudo:sudo ./setup_dns_cluster.sh
-
