-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
使用更优雅的代理逻辑,更换DNS,解决纯DNS回环问题,提高解析速度,更改AdGuardHome路径
- Loading branch information
Showing
6 changed files
with
111 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
id=AdGuardHome | ||
name=AdGuardHome For Magisk | ||
version=20231209 | ||
versionCode=5 | ||
author=top大佬(酷安)/twoone3 | ||
name=AdGuardHome for Magisk | ||
version=20231218 | ||
versionCode=6 | ||
author=twoone3 | ||
description=通过DNS层面过滤广告、防DNS劫持,后台地址http://127.0.0.1:3000,用户名/密码root |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,33 @@ | ||
until [ $(getprop sys.boot_completed) ]; do | ||
sleep 1 | ||
done | ||
MODDIR=${0%/*} | ||
chmod +x "$MODDIR/AdGuardHome" | ||
"$MODDIR/AdGuardHome" > "$MODDIR/AdGuardHome.log" 2>&1 & | ||
MODDIR="${0%/*}" | ||
ADG_DIR="$MODDIR/bin" | ||
chmod +x "$ADG_DIR/AdGuardHome" | ||
chown "root:net_admin" "$ADG_DIR/AdGuardHome" | ||
chown "root:net_admin" "$ADG_DIR/AdGuardHome.yaml" | ||
setuidgid "root:net_admin" "$ADG_DIR/AdGuardHome" >"$ADG_DIR/AdGuardHome.log" 2>&1 & | ||
# 读取配置文件的端口 | ||
adhome_port="$(cat "$MODDIR/AdGuardHome.yaml" | egrep '^ port: ' | sed -n 's/ port: //g;s/ //g;$p')" | ||
# 新建规则链 | ||
iptables -t nat -N ADHOME | ||
# 将 53 端口所有 upd tcp 流量转发到 adguard home | ||
iptables -t nat -A ADHOME -p udp --dport 53 -j REDIRECT --to-ports ${adhome_port} | ||
iptables -t nat -A ADHOME -p tcp --dport 53 -j REDIRECT --to-ports ${adhome_port} | ||
ip6tables -t nat -A ADHOME -p udp --dport 53 -j REDIRECT --to-ports ${adhome_port} | ||
ip6tables -t nat -A ADHOME -p tcp --dort 53 -j REDIRECT --to-ports ${adhome_port} | ||
# 将 ADHOME 规则添加到 OUTPUT | ||
iptables -t nat -A OUTPUT -j ADHOME | ||
adhome_port="$(cat "$ADG_DIR/AdGuardHome.yaml" | egrep '^ port: ' | sed -n 's/ port: //g;s/ //g;$p')" | ||
|
||
apply_rules() { | ||
# 新建规则链 | ||
iptables -t nat -N ADGUARD | ||
# 返回所有 AdGuardHome 的请求 | ||
iptables -t nat -A ADGUARD -m owner --uid-owner "root" --gid-owner "net_admin" -j RETURN | ||
# 将 53 端口所有 udp 流量转发到 adguard home | ||
iptables -t nat -A ADGUARD -p udp --dport 53 -j REDIRECT --to-ports ${adhome_port} | ||
ip6tables -t nat -A ADGUARD -p udp --dport 53 -j REDIRECT --to-ports ${adhome_port} | ||
# 将 ADGUARD 规则添加到 OUTPUT | ||
iptables -t nat -A OUTPUT -j ADGUARD | ||
} | ||
|
||
flush_rules() { | ||
iptables -t mangle -F ADGUARD | ||
iptables -t mangle -X ADGUARD | ||
|
||
ip6tables -t mangle -F ADGUARD | ||
ip6tables -t mangle -X ADGUARD | ||
} | ||
|
||
apply_rules |