Stock Android Fix: VPN + Private DNS in Android is broken. This auto-disables Private DNS on connect → restores on disconnect. EvolutionX is one outlier that has a built-in toggle, but not everyone wants to install custom ROMS.
DNS VPN Autotoggle automates this common headache:
VPN connects → Private DNS STAYS ON → DNS conflicts, leaks, no internet Manual fix: Settings → Network → Private DNS → Off → VPN works VPN disconnects → Forget to re-enable → Lose DNS protection
This simple module makes that headache go away, automatically!
- Automatically detects VPN interfaces (
tun*,ppp*,wg*,clat0,vnic*,ep*, `vep*'). - When VPN connects:
- Remembers your current
private_dns_modeand, if applicable,private_dns_specifier. - Sets Private DNS off to avoid conflicts or leaks.
- Remembers your current
- When VPN disconnects:
- Restores the previous mode exactly (e.g.
hostname,opportunistic, etc.). - Restores the previous hostname/specifier (e.g. your NextDNS DoT domain) when appropriate.
- Restores the previous mode exactly (e.g.
- Pauses polling when all networks are disabled or airplane mode is on.
- Robust error logging to
/data/adb/modules/dns-vpn-autotoggle/service.log. - No UI required; respects whatever you configured in Android’s Private DNS settings.
- Root: Magisk 24+ or KernelSU
- Android: 9 (Pie) or newer (Private DNS introduced in Android 9).
-
Download or build the module ZIP:
- Clone repo:
git clone https://github.com/ceryneian775/dns-vpn-autotoggle.git cd dns-vpn-autotoggle zip -r ../dns-vpn-autotoggle-install.zip *
- Clone repo:
-
In Magisk Manager:
- Go to Modules → Install from storage.
- Select
dns-vpn-autotoggle-install.zip. - Reboot.
-
(Optional but recommended) In Android:
- Go to Settings → Network & Internet → Private DNS.
- Set your preferred DoT provider hostname (e.g. NextDNS).
- The module will toggle between Off and your existing setting automatically.
- A Magisk
service.shruns as a late_start service on boot. - It:
- Checks if any known VPN interface is UP via
ip link. - Reads/writes
Settings.Global.private_dns_modeandprivate_dns_specifierusingsettingsas root. - Logs decisions and errors to:
/data/adb/modules/dns-vpn-autotoggle/service.log
- Checks if any known VPN interface is UP via
The script is designed to be conservative:
- It only changes Private DNS when VPN state transitions (connect/disconnect).
- It does not overwrite your hostname or mode outside those transitions.
- Log file:
/data/adb/modules/dns-vpn-autotoggle/service.log
If toggling does not work, check for:
- Permission/SELinux errors around the
settingscommand. - VPN interface names not covered in the default list (add them in
service.shif needed).
- Use Magisk Manager → Modules → Remove and reboot.
- No system files are patched; all changes are limited to the module directory and runtime settings.
This project is licensed under the GPL-2.0. See LICENSE for details.