Auto-switch VPN DNS (multiple VPN providers) with AdGuard filtering enabled

TLDR:
Is there currently a way to achieve the following three conditions together:

  1. Run multiple VPN provider instances (Surfshark, NordVPN, etc)
  2. Automatic VPN DNS switching; use the dedicated VPN DNS for whichever VPN is active
  3. Active Adguard Home filtering for ads/trackers

Longer Version:
Hardware: GL-MT3000 Beryl AX
Firmware Version: 4.8.1
VPN Providers: NordVPN & Surfshark (WireGuard)
Setup: 2 VPN tunnels

I’m experiencing a conflict between AdGuard Home filtering and VPN DNS functionality that prevents both from working simultaneously.

Scenario 1: “Allow Custom DNS to Override VPN DNS” = OFF

  • :white_check_mark: VPN DNS automatically changes when switching between VPN providers (good for streaming like BBC iPlayer)
  • :cross_mark: AdGuard Home receives DNS queries but no filtering occurs - ads/trackers are not blocked
  • :cross_mark: Query logs show no activity

Scenario 2: “Allow Custom DNS to Override VPN DNS” = ON

  • :white_check_mark: AdGuard Home filtering works perfectly (ads blocked, query logs active)
  • :cross_mark: VPN DNS doesn’t change when failover occurs, breaking geo-restricted streaming app that requires entry/exit IP addresses to be the same.

Current Router Configuration:

  • Override DNS Settings of All Clients: ON
  • AdGuard Home Handle Client Requests: ON
  • VPN Kill Switch: ON for failover tunnel, OFF for primary tunnel
  • DNS Rebinding Attack Protection: OFF

AdGuard Home Configuration:

  • Upstream DNS Servers: VPN DNS addresses when “Allow Custom DNS to Override VPN DNS” = ON
  • DNS Cache: 4MB with optimistic caching enabled

Solutions Already Attempted:

  1. Applied firewall rule reordering fix from this thread
  2. Updated to firmware v4.8.1 (from v4.8.0 stable)
  3. Toggled “AdGuard Home Handle Client Requests” (tried both states)

Expected Behaviour - I need AdGuard Home to:

  • Apply filtering/blocking rules to all DNS queries
  • Automatically switch VPN DNS depending on which VPN is active

Thanks!

Just to make sure, you saw both the initial solution I posted and the additional solution I posted later on (here: Sharing a solution for DNS leak with AdGuard Home handling client requests + connecting to VPN client - #16 by Integritas), right? The solution later on allows: (1) maintaining AdGuard Home filtering (2) using a VPN client and (3) being able to tap into the additional functionality of AdGuard Home when AdGuard Home handles client requests directly. If by chance you missed that other solution, check out that post, and the actual steps of the solution start at the point where the post says:

Thanks for your response.

I have indeed read your thread, but I still don't see a way to achieve the setup I described as it involves multiple active VPN instances from different providers. Unless I missed something...

I want to be able to have multiple running VPN instances from different providers, i.e., Surfshark, NordVPN, etc, whilst also seamlessly using the dedicated DNS for the VPN provider currently in use. All whilst still having Adguard Home adblock filtering working.

Ah, apologies. I only super skimmed your post right before needing to chase after my tiny humans, and I quickly replied in case that would help before I could read more fully. I guess I should've just waited to reply. I'm not aware of anything that would allow you to have the functionality you're after, absent it possibly being doable via custom scripting. It's the automatic switching you're after that makes it a bit of a challenge. I'll be interested to see if anyone else has something to offer here.

No worries! I knew I was asking for too much anyways :sweat_smile:

It will be a cool feature to have but I doubt there's a straightforward way of doing it. If Beryl could support out of the box in the next upgrade, that would be the icing on the cake!

I'm still hoping they'll add support for their UI to recognize and faithfully report on VLANs configured in LuCI. Right now, if you believe their UI, I have zero clients on my network. But that's false, and it's because I run VLANs. I get it would be hard to have their UI support adding or configuring VLANs, but for the UI not to faithfully report all clients/traffic on the network seems like an oversight. From what I've heard, it's because that portion of the UI is hard-coded to "see" only their out-of-the-box subnets (the main and guest networks). But it shouldn't be hard to tweak that to be more dynamic. But I'm apparently not the first to ask for this, and there's been no clear sign of movement or commitment to fix this. But I continue to hope. (I have a whole post asking about this if this interests you.)

Back to your Beryl AX. Have you found the 4.8.1 firmware to be reliable? I'm a fan of GL.iNet, but I typically don't jump straight on their newest firmware releases due to what I've seen from others when they do that.

No issues so far with the 4.8.1 firmware. Everything is running smoothly (touch wood).

It's the same thing with DHCP reservations. Anything in the GL GUI doesn't show in LuCI. It wouldn't surprise me if there's more disconnects.

I wouldn't hold your breath. GL firmware is designed for SOHO... to abstract away such 'troublesome' technical devils. /s

Any lovely humans from the GLinet staff that can shed some light on my question?
@bruce , @will.qiu maybe?

Hi,

I would like to clarify the question:

After enabling ADG, do the DNS request go to the corresponding VPN tunnel's DNS server, according to the effective tunnel (lets say Failover mode)?

Or do the DNS requests traffic of ADG (such as upstream server 8.8.8.8) go to the effective VPN tunnel?

These are the tests I've done:

  • “Allow Custom DNS to Override VPN DNS” = ON + 2 VPN Tunnels (Surfshark & NordVPN) + ADG enabled = all VPN tunnels use the upstream DNS, but this means when the VPN tunnels failover, the correct VPN DNS isn't being used. If Upstream DNS is left blank (same for fallback DNS), Cloudflare DNS is being used.
  • “Allow Custom DNS to Override VPN DNS” = OFF + 2 VPN Tunnels (Surfshark & NordVPN) + ADG enabled = the correct VPN DNS is being used when VPNs change but there's no ADG filtering taking place.

Therefore, the question still remains - how can I have 2 active VPN tunnels, from different VPN providers, whilst using their dedicated DNS. Add to that, we still need ADG to filter traffic for ad/trackers, etc.

As it currently stands, this doesn't seem to be possible? Unless there's another way of achieving this @bruce ?

Adguard DNS will override "vpn dns" if “Allow Custom DNS to Override VPN DNS” = on.
On the other hand, AdG upstream query can use a different tunnel according to the rule.

We'll address a bug for the rule that has ”Specified Connection Types“ from-settings.
You can try snapshot firmware if you set that.

In this scenario, please try to turn off DNS cache for AdG.

Thanks for the response @hansome.

Just to make sure I'm following your suggestion. Is VPN DNS auto-switching from Tunnel 1 to Tunnel 2 possible with “Allow Custom DNS to Override VPN DNS” = ON if "Specified Connection Types" if set? But what ADG Upstream DNS should be used in this case?

Ho risolto usando questo sistema

This setting has always been enabled for me. It doesn't solve the problem I described.

I'm happy to put this to rest if there's no resolution. Can someone from the glinet staff please confirm? @hansome @bruce @will.qiu

Not a very graceful solution, but it works.

  1. SSH into the router, edit the /etc/firewall.dns_order, remove the $append & $local_type for these lines.
    i.e. change these lines
        rules="-A adg_redirect -p tcp $local_type $append -j REDIRECT --to-ports 3053
-A adg_redirect -p udp $local_type $append -j REDIRECT --to-ports 3053"

to

        rules="-A adg_redirect -p tcp -j REDIRECT --to-ports 3053
-A adg_redirect -p udp -j REDIRECT --to-ports 3053"

This is to forward DNS requests from client devices to Adguard Home when not enabling “Allow Custom DNS to Override VPN DNS” & "Override DNS Settings of All Clients".

Note:Before modifying, remember to back up this file to avoid any accidental operations that may mess up the firewall settings. Otherwise, you will need to reset the router to recover.

  1. AdGuard Home DNS settings:
  • Upstream DNS servers:127.0.0.1:2153
  • Fallback DNS servers:127.0.0.1:2253

When the VPN type is Wireguard Client
The dnsmasq instance for the Primary Tunnel listens on port 2153
The dnsmasq instance for the Secondary Tunnel listens on port 2253

This is the configuration for Adguard Home to forward DNS requests to the corresponding VPN dnsmasq instance.

  1. Current Router Configuration:

DNS:

  • DNS Rebinding Attack Protection: OFF
  • Override DNS Settings of All Clients: OFF
  • Allow Custom DNS to Override VPN DNS: OFF

AdGuard Home:

  • Enable AdGuard Home: ON
  • AdGuard Home Handle Client Requests: ON

Thank you. Will verify this workaround!

Apologies for the radio silence. I have finally managed to implement the work around.

To test the workaround, I have excluded two devices from the Primary Tunnel to test the failover to SurfShark VPN on the Secondary Tunnel.

Now, when the failover happens, I can see the DNS from the Primary Tunnel in the IP Leak tests (Clouvider Limited). My assumption was that when we failover to the Secondary Tunnel, only that VPN DNS should be visible? Am I missing something?

Configuration recap:

  1. Changed /etc/firewall.dns_order

This solution only applies when the Primary Tunnel is truly disconnected — the dnsmasq instance tied to that tunnel will become unavailable.

For testing, consider deploying a WireGuard (WG) server inside your internal network.
That lets you simulate a Primary Tunnel failure simply by stopping the local WG server.