Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 25 additions & 8 deletions luci-app-openclash/root/etc/init.d/openclash
Original file line number Diff line number Diff line change
Expand Up @@ -251,18 +251,35 @@ revert_dns() {
uci -q set dhcp.@dnsmasq[0].localuse=1
uci -q commit dhcp
/etc/init.d/dnsmasq enabled && /etc/init.d/dnsmasq restart
masq_port=$(uci -q get dhcp.@dnsmasq[0].port)
if [ "$(nslookup www.apple.com 127.0.0.1:${masq_port} >/dev/null 2>&1 || echo $?)" = "1" ]; then
uci -q set openclash.config.default_resolvfile="/tmp/resolv.conf.d/resolv.conf.auto"
mkdir -p /tmp/resolv.conf.d
rm -rf /tmp/resolv.conf.d/resolv.conf.auto
touch /tmp/resolv.conf.d/resolv.conf.auto
cat >> "/tmp/resolv.conf.d/resolv.conf.auto" <<-EOF

# Only check DNS when dnsmasq is enabled
if /etc/init.d/dnsmasq enabled; then
masq_port=$(uci -q get dhcp.@dnsmasq[0].port)
if [ "$(nslookup www.apple.com 127.0.0.1:${masq_port} >/dev/null 2>&1 || echo $?)" = "1" ]; then
# DNS check failed, setup emergency DNS
uci -q set openclash.config.default_resolvfile="/tmp/resolv.conf.d/resolv.conf.auto"
mkdir -p /tmp/resolv.conf.d
rm -rf /tmp/resolv.conf.d/resolv.conf.auto
touch /tmp/resolv.conf.d/resolv.conf.auto

# Try to use LAN interface DNS first
lan_dns=$(uci -q get network.lan.dns)
if [ -n "$lan_dns" ]; then
# Use LAN DNS
echo "# Interface lan" >> "/tmp/resolv.conf.d/resolv.conf.auto"
for dns in $lan_dns; do
echo "nameserver $dns" >> "/tmp/resolv.conf.d/resolv.conf.auto"
done
else
# Fallback to hardcoded emergency DNS
cat >> "/tmp/resolv.conf.d/resolv.conf.auto" <<-EOF
# Interface lan
nameserver 119.29.29.29
nameserver 8.8.8.8
EOF
uci -q set dhcp.@dnsmasq[0].resolvfile="/tmp/resolv.conf.d/resolv.conf.auto"
fi
uci -q set dhcp.@dnsmasq[0].resolvfile="/tmp/resolv.conf.d/resolv.conf.auto"
fi
fi
fi
}
Expand Down