Problem with AdguardHome documentation installation script

I was following the documentation on https://openwrt.org/docs/guide-user/services/dns/adguard-home and after installing AGH there is a script starting with:

# Get the first IPv4 and IPv6 Address of router and store them in following variables for use during the script.
NET_ADDR=$(/sbin/ip -o -4 addr list br-lan | awk 'NR==1{ split($4, ip_addr, "/"); print ip_addr[1]; exit }')
NET_ADDR6=$(/sbin/ip -o -6 addr list br-lan scope global | awk '$4 ~ /^fd|^fc/ { split($4, ip_addr, "/"); print ip_addr[1]; exit }')
echo "Router IPv4 : ""${NET_ADDR}"
echo "Router IPv6 : ""${NET_ADDR6}"

Immediately I see an issue here, since the echos are returning empty for both variables when I run it in my router SSH as root:

root@OpenWrt:~# NET_ADDR=$(/sbin/ip -o -4 addr list br-lan | awk 'NR==1{ split($4, ip_addr, "/"); print ip_addr[1]; exit }')
root@OpenWrt:~# NET_ADDR6=$(/sbin/ip -o -6 addr list br-lan scope global | awk '$4 ~ /^fd|^fc/ { split($4, ip_addr, "/"); prin
t ip_addr[1]; exit }')
er IPv6 : ""${NET_ADDR6}"root@OpenWrt:~# echo "Router IPv4 : ""${NET_ADDR}"
Router IPv4 : 
root@OpenWrt:~# echo "Router IPv6 : ""${NET_ADDR6}"
Router IPv6 : 

Of course, when I run the rest, and then try to execute dnsmasq, it is now failing:

root@OpenWrt:~# dnsmasq -k -C /var/etc/dnsmasq.conf.cfg01411c 2>&1

dnsmasq: bad IP address at line 57 of /var/etc/dnsmasq.conf.cfg01411c

If I check line 57 of my config file (/var/etc/dnsmasq.conf.cfg01411c), it is:

dhcp-option=lan,3,

Is there a better command to get the IPv4 and IPv6 on the router so we can update the documentation? Otherwise it will break other people’s config as well.

You are most likely using VLANs and your device is not br-lan, but br-lan.X.

Try this:

dev=$(ifstatus lan | grep \"device | awk '{ print $2 }' | sed 's/[",]//g')
NET_ADDR=$(/sbin/ip -o -4 addr list $dev | awk 'NR==1{ split($4, ip_addr, "/"); print ip_addr[1]; exit }')
NET_ADDR6=$(/sbin/ip -o -6 addr list $dev scope global | awk '$4 ~ /^fd|^fc/ { split($4, ip_addr, "/"); print ip_addr[1]; exit }')
echo "Router IPv4 : ""${NET_ADDR}"
echo "Router IPv6 : ""${NET_ADDR6}"

Indeed @pavelgl I am, and those commands work correctly. Maybe it is good to add them also to Adguard docs? I imagine I am not the only person using VLANs…

I also noticed it is setting in the script option 3 and 6 to lan only, maybe it needs to find all dhcp interfaces and add as well.

The automatic extraction of the lan device name was added to the script.

Since one may want to not use AGH on all interfaces, added a note regarding manually setting DNS (for the additional interfaces) using option 6.

1 Like