Technitium DNS with failover over dns02
This commit is contained in:
parent
076234c4bd
commit
1efda446f3
13 changed files with 235 additions and 0 deletions
29
hosts/dns/dhcp-failover.sh
Normal file
29
hosts/dns/dhcp-failover.sh
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
src_dns_server=192.168.1.2
|
||||
# DHCP scopes to manage - put the name of each scope you have
|
||||
dhcp_scopes=("local-home") # Use this array for one or many scopes
|
||||
|
||||
echo "Checking primary Technitium server status"
|
||||
status_code=$(curl --write-out '%{http_code}' --silent --output /dev/null http://$src_dns_server:5380)
|
||||
|
||||
if [[ "$status_code" -ne 200 ]]; then
|
||||
echo "Primary DNS/DHCP server is not available. Enabling DHCP on the secondary server."
|
||||
action="enable"
|
||||
else
|
||||
echo "Primary DNS/DHCP server is available. Disabling DHCP on the secondary server."
|
||||
action="disable"
|
||||
fi
|
||||
|
||||
for scope in "${dhcp_scopes[@]}"; do
|
||||
echo "Executing API call to $action DHCP scope: $scope"
|
||||
response=$(curl -X POST "http://localhost:5380/api/dhcp/scopes/$action?token=$DNS1_API&name=$scope" \
|
||||
--silent --write-out "%{http_code}")
|
||||
|
||||
echo "HTTP response code: $response"
|
||||
if [[ "$response" == "200" ]]; then
|
||||
echo "Successfully $action DHCP for scope: $scope"
|
||||
else
|
||||
echo "Failed to $action DHCP for scope: $scope. Check the response body for details."
|
||||
fi
|
||||
done
|
||||
Loading…
Add table
Add a link
Reference in a new issue