;

林师傅的贼窝 每天都被折磨的想死

将废弃电脑变成软路由

前期准备工作

首先刷好 debian,这个有手就行,唯一的问题是镜像源比较慢,不管是国内源还是官方源,建议烧香拜佛之后再装,或者打电话给运营商通知他们要出国一下让他们取消你的墙

装好系统之后先更新软件源

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

启动 ssh 连接

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

修改固定 ip

这步很关键,不然 DHCP 到期换 ip ,所有以这个为网关的设备都会成为孤儿

vim /etc/network/interfaces

把原本的内容

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
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

# 检查
sysctl -p

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

上传文件

将我提供的文件中的 clash 文件夹和 mosdns 文件夹上传到 root 目录下

安装代理软件

安装 v2raya

  1. 添加公钥和软件源
# 报错的话可以试试逐条复制
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

添加软件源主要是 v2raya 的源不在官方源所以需要手动加一下

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

clash 永不为奴!!

  1. 添加 clash 的配置文件
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. 解压并移动到指定目录
tar -xf yacd.tar.xz
mkdir /etc/clash
mv public /etc/clash/yacd
  1. 下载 clash pre,ium
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. 移动到指定目录
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. 启动 systemd 守护进程服务 这个步骤主要防暴毙
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. 重新加载测试
systemctl daemon-reload
# 将系统DNS服务器指定为本地的IP192.168.234.3
vim /etc/resolved.conf
systemctl start clash
# 开机自启
systemctl enable clash
# 如果失败就不要用V3指令集的了

DNS 部分

安装 mosdns

  1. 下载 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
  1. 康康你的 53 端口有没有被后入
lsof -i :53
# 根据你占用53端口的进程名字来修改stop后面的参数
systemctl stop systemd-resolved.service
# 别忘了移除开机自启
systemctl disable systemd-resolved.service
# 检查一下
lsof -i :53
  1. 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

DNS 拦截广告只能欺负野鸡网站 ,面对 youtube 以及国内的爱优腾都是被操的走不动路的,此外 DNS 规则也很难找 ,博主本人已经变成了广告的形状(不是)

# 下载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

然后访问 http://你的ip:3000设置 adguardhome 就行了

终于结束了

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

软路由 Debian

软路由部署