Skip to content

Instantly share code, notes, and snippets.

@karoltheguy
Last active March 16, 2025 05:38
Show Gist options
  • Select an option

  • Save karoltheguy/2194de6ab18526b6597e4ad8b6e4264a to your computer and use it in GitHub Desktop.

Select an option

Save karoltheguy/2194de6ab18526b6597e4ad8b6e4264a to your computer and use it in GitHub Desktop.
"High Availability DNS Failover for Pi-hole / AdGuard using DNSdist
-- Bind DNS on all available interfaces on port 53
setLocal('0.0.0.0:53', {})
-- Set Access Control List to allow all IPv4 and IPv6 addresses
setACL({'0.0.0.0/0', '::/0'})
-- Bind the web server on port 8083 on all available interfaces
webserver("0.0.0.0:8083")
-- Set the web server configuration
setWebserverConfig({
acl = "0.0.0.0/0", -- Allow all IP addresses
dashboardRequiresAuthentication = false -- Disable authentication requirement for dashboard
})
-- Disable periodic security polling by setting an empty suffix
setSecurityPollSuffix("")
-- Admin control interface is currently commented out
-- controlSocket('0.0.0.0:52')
-- Define the primary and failover backend DNS servers
primaryBackend = newServer({
address = "192.168.3.1:53",
checkInterval = 5, -- Frequency to check server status (in seconds)
timeout = 1, -- Timeout for server responses (in seconds)
pool = "primary" -- Identifier for the primary backend pool
})
failoverBackend = newServer({
address = "172.0.0.2:53",
checkInterval = 5, -- Frequency to check server status (in seconds)
timeout = 1, -- Timeout for server responses (in seconds)
pool = "failover" -- Identifier for the failover backend pool
})
-- Function to select the backend pool based on the primary server's health.
-- Alternative names are: selectBackendPool, chooseDnsBackend, determineBackend, routeDnsRequest.
function selectBackendPool(dq)
-- Check if the primary backend is operational
if primaryBackend:isUp() then
-- Log diagnostic info (if required)
-- infolog("primary is up")
-- Return the action to use the primary backend pool
return DNSAction.Pool, "primary"
else
-- Log diagnostic info (if required)
-- infolog("primary is down")
-- Return the action to use the failover backend pool
return DNSAction.Pool, "failover"
end
end
-- Add an action rule to use our backend selection function for all DNS queries.
addAction(AllRule(), LuaAction(selectBackendPool))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment