Skip to content

Instantly share code, notes, and snippets.

@jhmartin
Last active January 8, 2025 17:26
Show Gist options
  • Save jhmartin/2b7c4e5e3d71c9697ea2e117cccaf7f8 to your computer and use it in GitHub Desktop.
Save jhmartin/2b7c4e5e3d71c9697ea2e117cccaf7f8 to your computer and use it in GitHub Desktop.
Mikrotik DNS failover
:global testDomain "dnstest.local" ;# Domain to test DNS resolution
:global queryServer "192.168.1.29" ;# Specific DNS server to query, local AdGuard instance
:global successDNS "192.168.1.29" ;# DNS server if the DNS request is successful, local AdGuard instance
:global failureDNS "9.9.9.11" ;# DNS server if the DNS request fails,
:log info "Testing DNS resolution for $testDomain using $queryServer."
# Perform a DNS lookup using a specific server
:do {:resolve domain-name="dnstest.local" server=$queryServer; /ip dns set servers=$successDNS; } on-error={/ip dns set servers=$failureDNS;}
@jhmartin
Copy link
Author

jhmartin commented Jan 8, 2025

Runs every 5 minutes in my Mikrotik router. If the local proxmox instance dies it fails DNS back to a public DNS so that the local network isn't perma-broken. dnstest.local is set up as a local DNS rewrite in AdGuard.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment