Clouldon Blog
    • 版块
    • 最新
    • 用户
    • 友链
    • 注册
    • 登录

    Win11安装Debian12.14软路由

    已定时 已固定 已锁定 已移动 软件教程
    1 帖子 1 发布者 142 浏览 1 关注中
    正在加载更多帖子
    • 从旧到新
    • 从新到旧
    • 最多赞同
    回复
    • 在新帖中回复
    登录后回复
    此主题已被删除。只有拥有主题管理权限的用户可以查看。
    • clouldonC 离线
      clouldon
      最后由 clouldon 编辑

      本教程以 Debian 12.14 在 VirtualBox / Hyper-V / VMware 中的虚拟机为例,采用桥接本机网卡方式,实现软路由功能(主要用于 LAN 侧转发 + 代理)。不需要配置 WAN 口,仅配置一个 LAN 接口。

      1. 安装 Debian 12.14 并启用 Root SSH 密码登录

      1. 下载 Debian 12.14 ISO 镜像(官方 netinst 或 full CD 均可)。

      2. 在虚拟机软件(VirtualBox / Hyper-V / VMware)中新建虚拟机:

        • 网络适配器:选择 桥接(Bridged) 到你的本机物理网卡(这样虚拟机能直接获得局域网 IP)。
        • CPU、内存、硬盘根据需求分配(推荐 2 核 + 1GB内存)。
        • 挂载 ISO 并启动安装。
      3. 安装过程中:

        • 选择语言、键盘等。
        • 分区:推荐整个磁盘(Guided - use entire disk)。
        • 设置 root 密码(重要!必须设置)。
        • 安装 SSH server(在任务选择中勾选 “SSH server”)。
      4. 安装完成后重启,进入系统。

      5. 启用 Root SSH 密码登录:

        nano /etc/ssh/sshd_config
        

        找到并修改以下两行(去掉注释 #

        PermitRootLogin yes
        PasswordAuthentication yes
        

        保存退出(Ctrl+O → Enter → Ctrl+X)。

        重启 SSH 服务:

        systemctl restart ssh
        

      2. 配置 LAN 接口(静态 IP 或 DHCP)

      1. 查看网卡名称:
      ip a
      

      例如:

      ens18
      

      或者:

      eth0
      
      1. 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顾名思义
        
      1. 保存后应用配置并重启网络及电脑:
        systemctl restart networking
        # 最好重启虚拟机
        reboot
        

      此时即可使用 SSH 客户端(推荐Netcatty;;或如 Xshell、MobaXterm、FinalShell 等),或cmd/powershell以 ssh root@IP 登录。

      1. 重启后验证:
        ip addr show
        ip route
        ping 119.29.29.29
        

      3. SSH 登录并开启 IPv4/IPv6 转发

      1. 使用 SSH 客户端以 root 登录虚拟机。

      2. 开启 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
      

      1. 验证转发是否开启:
      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 的 IP 192.168.1.11 前提有dns服务器
      • 点击「确定」保存。

      2. macOS 手动配置

      • 「系统设置」→「网络」→ 选择当前网络(如 Wi-Fi 或以太网)
      • 点击「详细信息」→「TCP/IP」
      • 配置 IPv4 为「手动」
        • IP 地址:192.168.1.51
        • 子网掩码:255.255.255.0
        • 路由器:192.168.1.11(Debian 的 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服务端
      1 条回复 最后回复 回复 引用

      你好!看起来您对这段对话很感兴趣,但您还没有一个账号。

      厌倦了每次访问都刷到同样的帖子?您注册账号后,您每次返回时都能精准定位到您上次浏览的位置,并可选择接收新回复通知(通过邮件或推送通知)。您还能收藏书签、为帖子顶,向社区成员表达您的欣赏。

      有了你的建议,这篇帖子会更精彩哦 💗

      注册 登录
      • 第一个帖子
        最后一个帖子