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.
- 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.
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.