5

Let say on my home Wifi, I want to use DNS server "X" and on work WiFI, I want to use another DNS-server: "Y", on cellular a server "Z" and so on. Is this possible to do this automatically? (Preferably without root) There seems to be loads of "DNS-apps" on play store, but I can't find any that do this. (have not tried them all)

4
  • If you disable the "private DNS" feature of Android you should get the matching DNS server for each connection automatically pushed as part of the IP information via DHCP.
    – Robert
    Commented Jul 16, 2021 at 9:55
  • 1
    I don't see how this helps? I know what DNS servers I want to use.
    – droidgren
    Commented Jul 16, 2021 at 10:38
  • So you don't want the standard DNS servers, but use special other DNS servers but for each connection a different one. That was not obvious from your question.
    – Robert
    Commented Jul 16, 2021 at 11:14
  • 1
    Exactly..I really tried to be as clear as possible but I guess I wasn't.
    – droidgren
    Commented Jul 17, 2021 at 7:47

2 Answers 2

10

The solution below will set Private DNS to "Automatic" on SSID: 'SSID-1' and 'SSID-2' Everything else will set Private DNS to your entered Private DNS hostname in settings.

  1. Install Tasker.

  2. Set up tasker as follow: (Change SSID-1/SSID2 to your name)

     Profile: AutoPrivateDNS
             State: Wifi Connected [ SSID:SSID-1/SSID-2 MAC:* IP:* Active:Any ]
         Enter: Anon
             A1: Custom Setting [ Type:Global Name:private_dns_mode Value:opportunistic Use Root:Off Read Setting To: ]
         Exit: Anon
             A1: Custom Setting [ Type:Global Name:private_dns_mode Value:hostname Use Root:Off Read Setting To: ]
    
  3. Grant Tasker WRITE_SECURE_SETTINGS permissions via ADB with following command:

adb shell pm grant net.dinglisch.android.taskerm android.permission.WRITE_SECURE_SETTINGS

  1. To set Private DNS to Off instead of 'Automatic' use the value 'Off' instead of 'opportunistic'.
  2. Tested with Android 11, Samsung S10E, no root.
1
  • Two updates for Tasker 6.1.32 with Android 13 on Pixel 7 Pro. First when it says Value:hostname above, that is literal. I thought it meant the desired hostname, so I used dns.adguard.com and it didn't work. Second, if you want to use mode off instead of opportunistic note that it is case sensitive. The text above suggests Off, but off is required to actually select the off state.
    – tim11g
    Commented Jun 11, 2023 at 19:17
3

You can setup a Tasker profile that is based on either a location or a WiFi network to trigger the task. Set the task to change the custom setting for private DNS with the hostname dependent on which network you are on.

1
  • 1
    Thanks, This worked fine! I posted a more detailed answer below how to do it.
    – droidgren
    Commented Jul 20, 2021 at 8:11

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .