Skip to content

Instantly share code, notes, and snippets.

@indraAsLesmana
Last active March 9, 2026 13:55
Show Gist options
  • Select an option

  • Save indraAsLesmana/e892ccee31276fd842158cab30949d02 to your computer and use it in GitHub Desktop.

Select an option

Save indraAsLesmana/e892ccee31276fd842158cab30949d02 to your computer and use it in GitHub Desktop.
How to Install AdGuard Home on OpenWrt: The Easy Way
#!/bin/sh
# Colors
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[0;33m'
NC='\033[0m' # No Color
echo -e "${YELLOW}Starting AdGuard Home Installation for OpenWrt...${NC}"
# Check for root
if [ "$(id -u)" -ne 0 ]; then
echo -e "${RED}This script must be run as root${NC}"
exit 1
fi
# Update Package Manager and Install Dependencies
echo -e "${YELLOW}Updating package lists and installing dependencies...${NC}"
if command -v apk >/dev/null 2>&1; then
echo -e "${YELLOW}Detected OpenWrt 25 or above (apk)...${NC}"
apk update
if [ $? -ne 0 ]; then
echo -e "${RED}apk update failed. Please check your internet connection.${NC}"
exit 1
fi
apk add ca-bundle wget-ssl curl tar
else
echo -e "${YELLOW}Detected OpenWrt 24 or below (opkg)...${NC}"
opkg update
if [ $? -ne 0 ]; then
echo -e "${RED}opkg update failed. Please check your internet connection.${NC}"
exit 1
fi
opkg install ca-bundle wget-ssl curl tar
fi
# Detect Architecture
echo -e "${YELLOW}Detecting architecture...${NC}"
ARCH=$(uname -m)
if [ "$ARCH" = "aarch64" ]; then
AGH_ARCH="arm64"
elif [ "$ARCH" = "x86_64" ]; then
AGH_ARCH="amd64"
elif [ "$ARCH" = "armv7l" ]; then
AGH_ARCH="armv7"
else
echo -e "${RED}Unsupported architecture: $ARCH${NC}"
echo -e "${YELLOW}Attempting to use generic armv5/v6 if applicable... (Not implemented in this script to be safe)${NC}"
# Fallback logic could go here, but safer to exit.
exit 1
fi
echo -e "${GREEN}Architecture detected: $AGH_ARCH${NC}"
# Prepare Directory
if [ -d "/opt/AdGuardHome" ]; then
echo -e "${YELLOW}AdGuard Home directory exists. Backing up...${NC}"
mv /opt/AdGuardHome /opt/AdGuardHome.bak.$(date +%F-%T)
fi
mkdir -p /opt/AdGuardHome
cd /opt
# Download Binary
echo -e "${YELLOW}Downloading AdGuard Home...${NC}"
wget "https://static.adguard.com/adguardhome/release/AdGuardHome_linux_${AGH_ARCH}.tar.gz" -O AdGuardHome.tar.gz
if [ ! -f "AdGuardHome.tar.gz" ]; then
echo -e "${RED}Download failed.${NC}"
exit 1
fi
echo -e "${YELLOW}Extracting...${NC}"
tar -xzvf AdGuardHome.tar.gz
rm AdGuardHome.tar.gz
# Configure dnsmasq
echo -e "${YELLOW}Moving dnsmasq to port 54...${NC}"
uci set dhcp.@dnsmasq[0].port="54"
uci commit dhcp
service dnsmasq restart
# Advertise AdGuard Home as DNS Server (Option 6)
echo -e "${YELLOW}Configuring DHCP to advertise AdGuard Home as DNS...${NC}"
IP=$(uci get network.lan.ipaddr | cut -d '/' -f 1)
uci -q delete dhcp.lan.dhcp_option
uci add_list dhcp.lan.dhcp_option="6,$IP"
uci commit dhcp
service dnsmasq restart
# Wait for port 53 to clear
echo -e "${YELLOW}Waiting for port 53 to clear...${NC}"
sleep 5
# Install Service
echo -e "${YELLOW}Installing AdGuard Home Service...${NC}"
cd /opt/AdGuardHome
./AdGuardHome -s install
# Start Service
echo -e "${YELLOW}Starting AdGuard Home...${NC}"
./AdGuardHome -s start
# Check Status
if pgrep AdGuardHome > /dev/null; then
echo -e "${GREEN}AdGuard Home Installed Successfully!${NC}"
IP=$(uci get network.lan.ipaddr | cut -d '/' -f 1)
echo -e "${GREEN}Access the setup wizard at: http://${IP}:3000${NC}"
echo -e "${YELLOW}NOTE: During setup, bind the Admin Interface to port 8080 or keep 3000.${NC}"
echo -e "${YELLOW}Bind the DNS Server to port 53.${NC}"
else
echo -e "${RED}AdGuard Home failed to start.${NC}"
exit 1
fi
@indraAsLesmana
Copy link
Author

update auto detect OpenWRT v25 with APK as package manager

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment