fix: 兼容 apt 版 smartdns 配置格式

This commit is contained in:
mango
2026-04-17 00:44:26 +08:00
parent 1476c1a52c
commit a51ddcbd42

View File

@@ -362,22 +362,15 @@ install_smartdns() {
mkdir -p /etc/smartdns mkdir -p /etc/smartdns
cat > /etc/smartdns/smartdns.conf << 'EOF' cat > /etc/smartdns/smartdns.conf << 'EOF'
# SmartDNS 配置 # SmartDNS 配置
# 监听端口
bind :53 bind :53
# 上游 DNS # 上游 DNS(简化格式,兼容 apt 版本)
server 8.8.8.8 -group default server 8.8.8.8
server 1.1.1.1 -group default server 1.1.1.1
server 223.5.5.5 -group default server 223.5.5.5
# 缓存配置 # 缓存配置
cache-size 4096 cache-size 4096
cache-persist yes
prefetch-domain yes
# 日志
log-level info
EOF EOF
echo -e "${GREEN}[被解锁机] smartdns 安装完成${NC}" echo -e "${GREEN}[被解锁机] smartdns 安装完成${NC}"
@@ -411,9 +404,13 @@ configure_smartdns_unlocker() {
} }
restart_smartdns() { restart_smartdns() {
# 先杀掉可能存在的旧进程
pkill -9 smartdns 2>/dev/null || true
sleep 1
systemctl daemon-reload systemctl daemon-reload
systemctl enable smartdns systemctl enable smartdns
systemctl restart smartdns systemctl start smartdns
# 设置系统 DNS # 设置系统 DNS
if command -v resolvconf &>/dev/null; then if command -v resolvconf &>/dev/null; then
@@ -421,6 +418,7 @@ restart_smartdns() {
else else
# 备份原 DNS 配置 # 备份原 DNS 配置
cp /etc/resolv.conf /etc/resolv.conf.bak 2>/dev/null || true cp /etc/resolv.conf /etc/resolv.conf.bak 2>/dev/null || true
chattr -i /etc/resolv.conf 2>/dev/null || true
echo "nameserver 127.0.0.1" > /etc/resolv.conf echo "nameserver 127.0.0.1" > /etc/resolv.conf
# 防止被覆盖 # 防止被覆盖
chattr +i /etc/resolv.conf 2>/dev/null || true chattr +i /etc/resolv.conf 2>/dev/null || true