Automating AdGuard Home Client IP Updates with Tasker and Termux

Share it:

In my previous article, I explained how I set up AdGuard Home on an Oracle Cloud Free Tier VM to block ads and inappropriate content across my devices. The setup worked perfectly, but there was one challenge left:

👉 My home internet connection uses a dynamic IP, meaning it changes from time to time. Since AdGuard Home only allows DNS queries from whitelisted clients, I needed a way to automatically update my allowed client IPs whenever my ISP assigned a new one.

That’s where Tasker, Termux, and the Termux:Tasker plugin came to the rescue.

Step 1: Install the Required Apps

First, I installed three apps on my Android phone:

Step 2: Create the Update Script in Termux

Inside Termux, I created a simple shell script that updates my current public IP into AdGuard Home’s Allowed Clients configuration.

Here’s the script that I used (with all server-specific details removed for obvious reasons😊):

#!/data/data/com.termux/files/usr/bin/bash
set -euo pipefail

# === Termux AdGuard Home IP Updater ===
# This script updates your current public IP
# into AdGuard Home's "Allowed Clients" list.

# --- Environment variables ---
ADGUARD_HOST="https://your-server-url"   # AdGuard Home server URL
ADGUARD_USER="username"                  # Username for login
ADGUARD_PASS="password"                  # Password for login

# --- Custom Host Configuration (as the DNS won't work until you update the IP, so to connect the Adguard server you don't have to resolve it.)---
# Define hostname and its IP (used to resolve properly in curl).
CUSTOM_AGH_HOST="your-custom-host"
CUSTOM_AGH_IP="your-server-ip"
CURL_RESOLVE=("--resolve" "$CUSTOM_AGH_HOST:443:$CUSTOM_AGH_IP")

# --- Cookie storage for authentication ---
COOKIE_FILE="$HOME/.tmp/agh_cookie.txt"
mkdir -p "$HOME/.tmp"

# 1. Get current public IP (using OpenDNS service).
CLIENT_IP=$(dig @208.67.222.222 myip.opendns.com +short)

# 2. Login to AdGuard Home (only if credentials provided).
if [[ -n "${ADGUARD_USER:-}" && -n "${ADGUARD_PASS:-}" ]]; then
    curl -s -c "$COOKIE_FILE" -X POST "${CURL_RESOLVE[@]}" "$ADGUARD_HOST/control/login" \
        -H "Content-Type: application/json" \
        -d "{\"name\":\"$ADGUARD_USER\",\"password\":\"$ADGUARD_PASS\"}" > /dev/null
    AUTH="-b $COOKIE_FILE"
else
    AUTH=""
fi

# 3. Fetch current list of allowed clients.
CURRENT_JSON=$(curl -s $AUTH "${CURL_RESOLVE[@]}" "$ADGUARD_HOST/control/access/list" || true)
CURRENT_CLIENTS=$(echo "$CURRENT_JSON" | jq -r '.allowed_clients | join(",")')

# If current IP already exists, exit gracefully.
if [[ $CURRENT_CLIENTS == *"$CLIENT_IP"* ]]; then
  exit 0
fi

# 4. Add new IP to the list of allowed clients.
NEW_CLIENTS=$(echo "$CURRENT_JSON" | jq --arg ip "$CLIENT_IP" '.allowed_clients + [$ip]' | jq -r '. | join(",")')

# 5. Send updated list back to AdGuard Home via API.
curl -s $AUTH -X POST "${CURL_RESOLVE[@]}" "$ADGUARD_HOST/control/access/set" \
  -H "Content-Type: application/json" \
  -d "{\"allowed_clients\":[\"$(echo "$NEW_CLIENTS" | sed 's/,/","/g')\"]}" > /dev/null

I saved this script in Termux under:

~/.termux/tasker/Update-adguard-full-termux-script.sh

and made it executable:

chmod +x ~/.termux/tasker/Update-adguard-full-termux-script.sh

Step 3: Install required package

To run the script, install update and install required packages by running below commands.

#Update the repo and upgrade binaries to the latest.
pkg update && pkg upgrade -y

#curl → Used to send API requests to AdGuard Home.
#jq → JSON parser, needed to process API responses.
#dnsutils → Provides the dig command to fetch your public IP.
pkg install curl jq dnsutils -y

#Some Termux installations don’t include all GNU tools. To be safe, install:
pkg install coreutils -y

Step 4: Configure Tasker Profile

Now I needed Tasker to automatically run this script whenever my phone connected to my home Wi-Fi.

Tasker prompted me to add a Task – I named it Wifi Connected.

Open Tasker.

Tap + to create a new Profile.

Choose State → Net → WiFi Connected.

Select my home WiFi SSID and set Active = Yes.

Tasker Wifi Profile

Step 5: Add Tasker → Termux:Tasker Action

Inside the new Task:

  1. Tap + to add an Action.
  2. Select Plugin → Termux:Tasker.
  3. In the configuration, enter the full path to my script:
/data/data/com.termux/files/home/.termux/tasker/Update-adguard-full-termux-script.sh
  1. Add the Working Directory to the directory where your script is located.
  2. Save and back out.
Tasker Action Configuration

Note: You need to allow Tasker permission to run script in Termux environment. You can do this by going to Tasker app info –> Permission –> Additional Permission, then allow Run commands in Termux environment

Android Termux Tasker background permission settings

Step 6: Testing the Automation

To test it, I toggled WiFi off and back on. As soon as my phone connected to my home WiFi, Tasker triggered the Termux script. The script fetched my current public IP and updated AdGuard Home’s Allowed Clients list automatically.

No more worrying about dynamic IPs breaking my DNS setup.

Optional Improvements

  • Notification: Add a Tasker notification confirming the update was successful.
  • Cron-style updates: Run the script on a schedule (e.g., every 6 hours) to catch IP changes outside of WiFi reconnects.
  • Error handling: Add logging to the script so you can debug if something fails.

Final Thoughts

This setup combined the best of both worlds:

  • AdGuard Home on Oracle Cloud → full control over DNS, ads, and content filtering.
  • Tasker + Termux automation → automatic IP updates without manual intervention.

Now my family enjoys safe, ad-free browsing without me worrying about IP changes. In just a few steps, I built a self-healing system that keeps AdGuard Home always in sync with my home network.