Skip to content

ceryneian775/dns-vpn-autotoggle

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

DNS VPN Autotoggle

Module Version KernelSU Magisk Android License

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!


Features

  • Automatically detects VPN interfaces (tun*, ppp*, wg*, clat0, vnic*, ep*, `vep*').
  • When VPN connects:
    • Remembers your current private_dns_mode and, if applicable, private_dns_specifier.
    • Sets Private DNS off to avoid conflicts or leaks.
  • 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.
  • 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.

Requirements

  • Root: Magisk 24+ or KernelSU
  • Android: 9 (Pie) or newer (Private DNS introduced in Android 9).

Installation

  1. 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 *
      
  2. In Magisk Manager:

    • Go to Modules → Install from storage.
    • Select dns-vpn-autotoggle-install.zip.
    • Reboot.
  3. (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.

How It Works

  • A Magisk service.sh runs 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_mode and private_dns_specifier using settings as root.
    • Logs decisions and errors to:
      • /data/adb/modules/dns-vpn-autotoggle/service.log

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.

Logging & Debugging

  • Log file:
    /data/adb/modules/dns-vpn-autotoggle/service.log

If toggling does not work, check for:

  • Permission/SELinux errors around the settings command.
  • VPN interface names not covered in the default list (add them in service.sh if needed).

Uninstall

  • Use Magisk Manager → Modules → Remove and reboot.
  • No system files are patched; all changes are limited to the module directory and runtime settings.

License

This project is licensed under the GPL-2.0. See LICENSE for details.

About

DNS VPN Autotoggle

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages