原文链接:https://blog.sifulin.top/p/debian%E6%90%AD%E5%BB%BAdns%E5%92%8C%E4%BB%A3%E7%90%86%E6%9C%8D%E5%8A%A1%E5%99%A8/

https://www.bilibili.com/opus/980740539470053445?jump_opus=1

前期准备工作

apt-get update
apt-get install -y vim wget curl tar zip sudo
##########################################################################
开启第三方登录
nano /etc/ssh/sshd_config service ssh restart


设置东八区与中文
timedatectl set-timezone Asia/Shanghai
# 追加本地语言配置 echo "zh_CN.UTF-8 UTF-8" >> /etc/locale.gen
# 重新配置本地语言 dpkg-reconfigure locales
# 指定本地语言 export LC_ALL="zh_CN.UTF-8"
#中文的设置


常用软件安装
apt install zsh git vim curl -y sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"


添加未知命令提示工具
nano ~/.zshrc
. /etc/zsh_command_not_found
#在文件末尾添加以上内容
source ~/.zshrc
#配置生效###########

############################################

修改 ssh 配置文件

echo "PermitRootLogin yes" >> /etc/ssh/sshd_config # 重启ssh /etc/init.d/ssh restart

修改固定 ip

vim /etc/network/interfaces

变成如下形式

1# 默认的
auto lo
iface lo inet loopback
allow-hotplug ens35
iface ens35 inet dhcp
# 修改为
iface ens35 inet static
address 192.168.1.100
netmask 255.255.255.0
gateway 192.168.1.1
# 要使用ipv6公网访问的话再添加并确保上级路由器开启了dhcpv6
iface ens35 inet6 dhcp

开启 ipv4 转发

# 填写如下内容开启ipv4转发,并关闭ipv6
echo "net.ipv4.ip_forward=1 net.ipv6.conf.all.disable_ipv6 = 1" >> /etc/sysctl.conf
# 如果你像我一样没有公网ipv4还想顺畅外网访问家中服务,就要把ipv6开启填这个
echo "net.ipv4.ip_forward=1" >> /etc/sysctl.conf
(或者)
vim /etc/sysctl.conf
net.ipv4.ip_forward=1(去掉#)
net.ipv6.conf.all.forwarding = 1(去掉#,可去可不去)
# 检查 sysctl -p # 清DNS缓存(debian12不需要)
systemctl restart
systemd-resolved.service
# 重启
reboot
# 检测
ip ip addr

点击下载配置文件

这步很关键,一定要上传,把我给的压缩包里面的 clash 文件夹和 mosdns 文件夹上传到 root 文件夹下

方案一、安装 v2raya

添加公钥和软件源

# 报错的话可以试试逐条复制
wget -qO - https://apt.v2raya.org/key/public-key.asc | sudo tee /etc/apt/keyrings/v2raya.asc

echo "deb [signed-by=/etc/apt/keyrings/v2raya.asc] https://apt.v2raya.org/ v2raya main" | sudo tee /etc/apt/sources.list.d/v2raya.list

sudo apt update

安装

sudo apt install v2raya v2ray #v2ray内核
sudo apt install v2raya xray #xray内核
# 启动并设置自启 sudo systemctl start v2raya.service
# 开机自启 sudo systemctl enable v2raya.service

方案二、安装mihomo

# 下载Country.mmdb文件(去github上下载最新)

wget https://github.com/Dreamacro/maxmind-geoip/releases/latest/download/Country.mmdb

# 下载MetaCubeX面板(去github上找最新)

wget https://github.com/MetaCubeX/metacubexd/releases/download/v1.149.0/compressed-dist.tgz

# 解压文件到指定目录

mkdir /etc/mihomo -p
mkdir /etc/mihomo/ui
tar -xf /root/compressed-dist.tgz -C /etc/mihomo/ui

(config.yaml文件内需添加external-ui: /etc/mihomo/ui

# 下载mihomo并解压

wget https://github.com/MetaCubeX/mihomo/releases/download/v1.18.8/mihomo-linux-386-v1.18.8.gz
gzip -d mihomo-linux-386-v1.18.8.gz

# 重命名mihomo并移动到目录,赋予执行权限

mv mihomo-linux-386-v1.18.8 /usr/local/bin/mihomo
mv Country.mmdb /etc/mihomo/
chmod +x /usr/local/bin/mihomo

# 把config.yaml扔到/etc/mihomo/目录里

#手动运行一次观察是否正常

sudo /usr/local/bin/mihomo -d /etc/mihomo

# 进程守护

vim /etc/systemd/system/mihomo.service

填入以下内容

[Unit]

Description=mihomo Daemon, Another Clash Kernel.

After=network.target NetworkManager.service systemd-networkd.service iwd.service

[Service]

Type=simple

LimitNPROC=500

LimitNOFILE=1000000

CapabilityBoundingSet=CAP_NET_ADMIN CAP_NET_RAW CAP_NET_BIND_SERVICE CAP_SYS_TIME CAP_SYS_PTRACE CAP_DAC_READ_SEARCH

AmbientCapabilities=CAP_NET_ADMIN CAP_NET_RAW CAP_NET_BIND_SERVICE CAP_SYS_TIME CAP_SYS_PTRACE CAP_DAC_READ_SEARCH

Restart=always

ExecStartPre=/usr/bin/sleep 1s

ExecStart=/usr/local/bin/mihomo -d /etc/mihomo

ExecReload=/bin/kill -HUP $MAINPID

[Install]

WantedBy=multi-user.target

⬆️框框,复制粘贴保存

# 重新加载测试

systemctl daemon-reload

systemctl enable mihomo

systemctl start mihomo

systemctl stop mihomo

systemctl status mihomo

DNS篇

安装 mosdns

下载 mosdns

wget https://github.com/IrineSistiana/mosdns/releases/download/v5.1.3/mosdns-linux-amd64.zip

创建所需目录

mkdir /etc/mosdns
mkdir /var/mosdns
touch /var/disable-ads.txt
mv mosdns/etc/mosdns/* /etc/mosdns
mv mosdns/var/mosdns/* /var/mosdns
mv mosdns/v2dat /opt
chmod +x /opt/v2dat

确保 53 端口没有被占用

lsof -i :53
# 根据你占用53端口的进程名字来修改stop后面的参数
systemctl stop systemd-resolved.service
# 别忘了移除开机自启
systemctl disable systemd-resolved.service
# 检查一下
lsof -i :53

安装 mosdns

# 解压
unzip -o -d mosdns mosdns-xxx-xxx.zip
# 把mosdns软件移到绝对工作目录
mv /root/mosdns/mosdns /usr/bin/
chmod +x /usr/bin/mosdns
# mosdns service install -d 工作目录绝对路径 -c 配置文件路径
mosdns service install -d /usr/bin -c /etc/mosdns/config.yaml
# 启动mosdns并设置开机自启
mosdns service start
systemctl enable mosdns.service
# 检查状态
systemctl status mosdns.service

安装 adguardhome

安装 adguardhome 的代码

# 下载AdGuardHome到本机,三选一都是安装脚本,能用就行
curl -s -S -L https://raw.githubusercontent.com/AdguardTeam/AdGuardHome/master/scripts/install.sh | sh -s -- -v

wget --no-verbose -O - https://raw.githubusercontent.com/AdguardTeam/AdGuardHome/master/scripts/install.sh | sh -s -- -v

fetch -o - https://raw.githubusercontent.com/AdguardTeam/AdGuardHome/master/scripts/install.sh | sh -s -- -v
# 启动
systemctl start AdGuardHome
# 状态
systemctl status AdGuardHome
# 开机自启
systemctl enable AdGuardHome
# 重启
systemctl restart AdGuardHome
# 停止
systemctl stop AdGuardHome

收尾

vim /etc/resolv.conf

编辑cron

mkdir /etc/mycron
mv /clash/clash_update.sh /etc/mycron
mv /mosdns/mosdns_update.sh /etc/mycron
chmod +x /etc/mycron/mosdns_update.sh

添加

echo "30 4 * * * root /etc/mycron/mosdns_update.sh" >> /etc/crontab