A lightweight Android application that automatically toggles "Private DNS" settings based on your Wi-Fi connection.
Let's consider a scenario where you have Pi-hole set up in your home, and you want to use it instead of your Private DNS provider while connected to your local network. However, at the same time, you want to enable your Private DNS when outside your home network. Well, this is what this app is for, it automates the switch between them.
Since Android does not natively allow you to disable "Private DNS" for specific Wi-Fi networks while keeping it enabled for mobile data, this app solves that problem by running a background service that detects your connection state.
- At Home: Disables Private DNS (allowing you to use a local Pi-hole).
- Away: Enables Private DNS (using NextDNS, AdGuard) for security on public networks.
Build the APK using Android Studio or download the release and install it on your device.
Because changing system settings is a secure action, you must grant the app permission via ADB once after installation.
Connect your phone to your PC and run:
adb shell pm grant com.rickmschulz.dnsautoswitcher android.permission.WRITE_SECURE_SETTINGS
Tip
If you need help with ADB, this page can help you.
To ensure the app works reliably in the background, open the app's settings page and:
- Disable
Manage app if unused. - Set Battery usage to
Unrestricted. - Grant Location permission and select
Allow all the time.
Google requires any app that reads the connected Wi-Fi network's SSID or BSSID to have either ACCESS_COARSE_LOCATION or ACCESS_FINE_LOCATION permission. Without this permission, Android will return <unknown ssid> instead of the actual network name. Since DNS Auto Switcher identifies your home network by its SSID, location permission is required for the app to detect when you're connected to your Wi-Fi and automatically toggle Private DNS settings.
- Open the app.
- Enter your Home Wi-Fi SSID (e.g.,
MyHomeWiFi). - Enter your Private DNS Hostname (e.g.,
12345.dns.nextdns.ioordns.adguard-dns.com). - Click Save & Start Service.
- DNSService.java: A foreground service that listens for network changes using
ConnectivityManager.NetworkCallback. - BootReceiver.java: Automatically restarts the monitoring service when the phone reboots.
- Permissions: Uses
WRITE_SECURE_SETTINGSto modifySettings.Global.private_dns_mode.
v1.1
- Fixed: The app was only partially working as intended. This release fixes the underlying issues and restores full functionality.
- Note: This version is undergoing active testing over the next few days to ensure long-term stability.
This app targets Android 9.0 (Pie) and higher, as the Private DNS feature was introduced in API 28.
This project is licensed under the GNU General Public License v3.0 (GPLv3). This ensures that the software remains free and open source for everyone. You are free to use, modify, and distribute this software in compliance with the license terms.