debian上安装mosdns进行分流,clash/v2raya进行代理实现丝滑的科学上网

 



前期准备工作

1
2
3
apt-get update

apt-get install -y vim wget curl tar zip sudo

修改 ssh 配置文件

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

修改固定 ip

1
vim /etc/network/interfaces

变成如下形式

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
# 默认的
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 转发

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
# 填写如下内容开启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

# 检查
sysctl -p

# 清DNS缓存(debian12不需要)
systemctl restart systemd-resolved.service
# 重启
reboot
# 检测ip
ip addr

上传文件

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

安装 v2raya

添加公钥和软件源

1
2
3
4
5
6
# 报错的话可以试试逐条复制
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

安装

1
2
3
4
5
6
sudo apt install v2raya v2ray #v2ray内核
sudo apt install v2raya xray  #xray内核
# 启动并设置自启
sudo systemctl start v2raya.service
# 开机自启
sudo systemctl enable v2raya.service

安装 clash

下载 clash 配置文件

1
2
3
4
5
wget -O config.yaml '你机场的订阅链接&flag=clash'
# 下载Country.mmdb文件(去github上下载最新)
wget https://github.com/Dreamacro/maxmind-geoip/releases/latest/download/Country.mmdb
# 下载yacd面板(去github上找最新)
wget https://github.com/haishanh/yacd/releases/download/v0.3.8/yacd.tar.xz

解压并移动到指定目录

1
2
3
tar -xf yacd.tar.xz
mkdir /etc/clash
mv public /etc/clash/yacd

下载 clash premium

1
2
wget https://github.com/Dreamacro/clash/releases/download/premium/clash-linux-amd64-2023.08.17.gz
gzip -d clash-linux-amd64-2023.08.17.gz

移动文件到指定目录

1
2
3
4
5
6
7
mv  clash-linux-amd64-2023.08.17 /usr/local/bin/clash
mkdir /etc/clash
mv config.yaml /etc/clash/
mv Country.mmdb /etc/clash/
mv clash/template.yaml /etc/clash
# 赋予执行权限
chmod +x /usr/local/bin/clash

安装进系统服务

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
echo "[Unit]
Description=Clash daemon, A rule-based proxy in Go.
After=network-online.target

[Service]
Type=simple
Restart=always
ExecStart=/usr/local/bin/clash -d /etc/clash

[Install]
WantedBy=multi-user.target" >> /etc/systemd/system/clash.service

重新加载

1
2
3
4
5
6
7
systemctl daemon-reload
# 将系统DNS服务器指定为本地的IP192.168.234.3
vim /etc/resolved.conf
systemctl start clash
# 开机自启
systemctl enable clash
# 如果失败就不要用V3指令集的了

自动更新订阅文件

配合 shell 脚本和 template.txt 文件使用

安装 mosdns

下载 mosdns

1
2
# 报错的话可以试试把梯子关了
wget https://github.com/IrineSistiana/mosdns/releases/download/v5.1.3/mosdns-linux-amd64.zip

创建所需目录

1
2
3
4
5
6
7
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 端口没有被占用

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

安装 mosdns

1
2
3
4
5
# 解压
unzip -o -d mosdns mosdns-xxx-xxx.zip
# 把mosdns软件移到绝对工作目录
mv /root/mosdns/mosdns /usr/bin/
chmod +x /usr/bin/mosdns
1
2
3
4
5
6
7
8
# 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 的代码

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
# 下载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

收尾

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
vim /etc/resolv.conf

# 将dns服务器设置为旁路由ip
nameserver 192.168.50.5

# 编辑cron
mkdir /etc/mycron
mv /clash/clash_update.sh /etc/mycron
mv /mosdns/mosdns_update.sh /etc/mycron
chmod +x /etc/mycron/clash_update.sh
chmod +x /etc/mycron/mosdns_update.sh
# 添加
echo "30 4 * * * root /etc/mycron/mosdns_update.sh
35 4 * * * root /etc/mycron/clash_update.sh" >> /etc/crontab

评论

此博客中的热门博文

dae(大鹅) 内核级高性能透明代理工具- 安装和基本配置笔记

【docker部署】daed(Dashboard) 内核级高性能透明代理工具- 大鹅 Dashboard WEB项目

通过Workers脚本部署设置,手把手带您实现免费高速科学上网,无障碍访问奈菲,ChatGPT