Win11安装Debian12.14软路由
-
本教程以 Debian 12.14 在 VirtualBox / Hyper-V / VMware 中的虚拟机为例,采用桥接本机网卡方式,实现软路由功能(主要用于 LAN 侧转发 + 代理)。不需要配置 WAN 口,仅配置一个 LAN 接口。
1. 安装 Debian 12.14 并启用 Root SSH 密码登录
-
下载 Debian 12.14 ISO 镜像(官方 netinst 或 full CD 均可)。
-
在虚拟机软件(VirtualBox / Hyper-V / VMware)中新建虚拟机:
- 网络适配器:选择 桥接(Bridged) 到你的本机物理网卡(这样虚拟机能直接获得局域网 IP)。
- CPU、内存、硬盘根据需求分配(推荐 2 核 + 1GB内存)。
- 挂载 ISO 并启动安装。
-
安装过程中:
- 选择语言、键盘等。
- 分区:推荐整个磁盘(Guided - use entire disk)。
- 设置 root 密码(重要!必须设置)。
- 安装 SSH server(在任务选择中勾选 “SSH server”)。
-
安装完成后重启,进入系统。
-
启用 Root SSH 密码登录:
nano /etc/ssh/sshd_config找到并修改以下两行(去掉注释
#PermitRootLogin yes PasswordAuthentication yes保存退出(Ctrl+O → Enter → Ctrl+X)。
重启 SSH 服务:
systemctl restart ssh
2. 配置 LAN 接口(静态 IP 或 DHCP)
- 查看网卡名称:
ip a例如:
ens18或者:
eth0- Debian 默认使用
/etc/network/interfaces管理网络。
编辑配置文件:
nano /etc/network/interfaces配置示例(静态 IP,适合软路由):
# This file describes the network interfaces # and how to activate them source /etc/network/interfaces.d/* # The loopback network interface auto lo iface lo inet loopback # LAN 接口(根据虚拟机网卡名称替换见上方名称) auto eth0 # 这里使用eth0示例 iface eth0 inet static # static静态 address 192.168.1.11/24 # 软路由 LAN IP gateway 192.168.1.1 # 上级网关(通常是你的主路由器 IP) dns-nameservers 119.29.29.29 223.5.5.5 #dns填入 iface eth0 inet6 dhcp #DHCPv6 有v6情况才写入 post-up sysctl -w net.ipv6.conf.eth0.accept_ra=2 >/dev/null 2>&1 #RA 获取默认v6路由上网- 说明:
address:设置本机 LAN IP。gateway:上级路由器(主路由器)的 IP,用于软路由访问外网(可选,根据需求)。- 如果想用 DHCP,改为:
- 注意改为DHCP需要在路由器根据MAC地址查看IP才能连接SSH;或者虚拟机连接,查看ip
auto eth0 iface eth0 inet dhcp # dhcp顾名思义
- 保存后应用配置并重启网络及电脑:
systemctl restart networking # 最好重启虚拟机 reboot
此时即可使用 SSH 客户端(推荐
Netcatty;;或如 Xshell、MobaXterm、FinalShell 等),或cmd/powershell以 ssh root@IP 登录。- 重启后验证:
ip addr show ip route ping 119.29.29.29
3. SSH 登录并开启 IPv4/IPv6 转发
-
使用 SSH 客户端以 root 登录虚拟机。
-
开启 IPv4/IPv6 转发(必需):
sudo cp /etc/sysctl.conf /etc/sysctl.conf.bk_$(date +%Y%m%d_%H%M%S) && \ sudo tee /etc/sysctl.conf << 'EOF' net.ipv4.ip_forward=1 net.ipv4.conf.all.forwarding=1 net.ipv6.conf.all.forwarding=1 net.ipv4.tcp_congestion_control=bbr net.core.default_qdisc=fq EOF sudo sysctl -p
- 验证转发是否开启:
sysctl net.ipv4.ip_forward sysctl net.ipv6.ip_forward应输出
net.ipv4.ip_forward = 1;net.ipv6.ip_forward = 1。4. 启用代理(二选一)
选项 A:OPENPPP2(推荐隧道工具)
内容 链接 安装脚本 https://github.com/picetor/openppp2_install 原版仓库 https://github.com/liulilittle/openppp2 改版,更多特性 https://github.com/Miaocchi/openppp2 自编译版本,兼容openwrt https://github.com/picetor/openppp2 拉取脚本
直连 GitHub(海外服务器或网络良好)
wget -4 -O ppp_install.sh https://raw.githubusercontent.com/picetor/openppp2_install/main/ppp_install.sh && chmod +x ppp_install.sh && ./ppp_install.sh
使用Github加速
wget -4 -O ppp_install.sh https://git.apad.pro/https://raw.githubusercontent.com/picetor/openppp2_install/main/ppp_install.sh && chmod +x ppp_install.sh && ./ppp_install.sh运行后进入交互菜单,根据提示选择客户端模式安装配置,需准备服务端信息、修改启动脚本
/opt/ppp/ppp.sh;工作目录opt/ppp选项 B:Clash for Linux
项目地址: https://github.com/wnlen/clash-for-linux
Github直连git clone --branch master --depth 1 https://github.com/wnlen/clash-for-linux.git cd clash-for-linux bash install.sh
Github加速
git clone --branch master --depth 1 ``` https://ghfast.top/https://github.com/wnlen/clash-for-linux.git cd clash-for-linux bash install.sh安装完成后使用
clashon启动,clashctl管理订阅、节点等。详情看原仓库客户端配置方法
1. Windows 手动配置
- 打开「控制面板」→「网络和共享中心」→「更改适配器设置」
- 右键点击当前使用的网卡(以太网或 WLAN)→「属性」
- 双击「Internet 协议版本 4 (TCP/IPv4)」
- 选择「使用下面的 IP 地址」:
- IP 地址:与 Debian 同网段,例如
192.168.1.50 - 子网掩码:
255.255.255.0 - 默认网关:
192.168.1.11(Debian 的 IP) - DNS 服务器:可填写
223.5.5.5、119.29.29.29;;或 Debian 的 IP192.168.1.11前提有dns服务器
- IP 地址:与 Debian 同网段,例如
- 点击「确定」保存。
2. macOS 手动配置
- 「系统设置」→「网络」→ 选择当前网络(如 Wi-Fi 或以太网)
- 点击「详细信息」→「TCP/IP」
- 配置 IPv4 为「手动」
- IP 地址:
192.168.1.51 - 子网掩码:
255.255.255.0 - 路由器:
192.168.1.11(Debian 的 IP)
- IP 地址:
- DNS 可手动添加
223.5.5.5等 - 点击「好」保存。
4. 手机 / 平板(Android / iOS)
- 进入 Wi-Fi 设置,长按当前连接的 Wi-Fi →「修改网络」或「配置网络」
- 将「IP 设置」从 DHCP 改为「静态」
- IP 地址:例如
192.168.1.53 - 网关:
192.168.1.11(Debian 的 IP) - DNS:
223.5.5.5等 - 保存。
验证客户端是否通过软路由
在客户端上打开浏览器,访问
https://ip.skk.moe或https://ipcheck.ing/,显示的 IP 应为代理出口 IP(而非上级路由的 IP)。也可在客户端命令行执行:
tracert 119.29.29.29 # Windows traceroute 119.29.29.29 # Linux/macOS第一跳应显示
192.168.1.11(Debian 软路由地址)。
最终结构
+-------------+ | 上级路由 | +-------------+ │ │ (桥接网络) ▼ +-------------+ | Debian 12.14| | 软路由 | +-------------+ │ ├── openppp2 │ 或 └── Clash for Linux │ │ (LAN 同网段) ▼ +-------------+ | 客户端 | | (PC/手机等) | +-------------+
后续常用操作:
- 查看网络:
ip addr、ip route - 编辑网络接口
nano /etc/network/interfaces - 重启网络:
systemctl restart networking - 安装mosdns本地DNS服务端
-