V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
juzisang
V2EX  ›  分享发现

搬家导致公网 IP 无了之后,我琢磨出的公司办公机搭配 Clash,访问家庭网络的方案

  •  1
     
  •   juzisang · 20 天前 · 1070 次点击

    有什么优势

    • 通过家里的局域网 IP 访问设备
    • 解决公司内部网络,内部 DNS 问题
    • 直连网络,流量不需要经过服务器中转
    • 和 Clash 配合,不需要再装其它 VPN 软件
    • 相比于 zerotier tailscale ,没有 QoS 的问题
    • 安全,不需要对外暴露端口
    • 适合多对一的情况

    前提:搞清楚 NAT 类型,确定能够打洞穿透才行

    pFXNYiF.png

    1. 准备

    • Clash.Verge
    • FRP
    • 一台云服务器
      • frps 负责 P2P 打洞,失败也可以作为降级,Frp 提供穿透失败走中转的策略
    • 家里
      • frpc
      • socks-server
    • 公司
      • frpc
      • clash

    2. Frp 配置

    2.1 云服务器 Frps 配置

    frps.toml

    bindPort = 7000
    

    docker-compose.yml

    version: '3.5'
    
    services:
      frps:
        image: snowdreamtech/frps:0.56.0
        networks:
          - cluster
        environment:
          - TZ=Asia/Shanghai
        volumes:
          - /etc/timezone:/etc/timezone:ro
          - /etc/localtime:/etc/localtime:ro
        configs:
          - source: frps_config
            target: /etc/frp/frps.toml
        ports:
          - target: 7000
            published: 7000
    configs:
      frps_config:
        file: ./frps.toml
    

    2.2 家里

    • 部署 socks 服务
      • 我是用的 openwrt passwall 自带的

    frpc.toml

    # frps 部署地址
    serverAddr = "xxxx"
    serverPort = 7000
    
    [[proxies]]
    name = "socks-proxies"
    # frp xtcp 才支持 p2p 打洞穿透
    type = "xtcp"
    # 秘钥,公司的 frpc 会用到
    secretKey = "xxxx"
    # 填你的 socks 所在设备的 ip port
    localIP = "192.168.5.2"
    localPort = 10080
    

    2.3 公司

    frpc.toml

    # frps 部署地址
    serverAddr = "xxxx"
    serverPort = 7000
    
    [[visitors]]
    # 随便取
    name = "socks_visitor"
    # 和家里保持一致
    type = "xtcp"
    serverName = "socks-proxies"
    secretKey = "xxxx"
    # 绑定到本地的端口
    bindAddr = "0.0.0.0"
    bindPort = 10080
    # 定时轮询,保持连接
    # keepTunnelOpen = true
    

    运行

     docker run --restart=always -p 10080:10080 -d -v ./frpc.toml:/etc/frp/frpc.toml --name frpc snowdreamtech/frpc
    

    3. Clash 配置

    在 Clash-Verge 中开启 Tun 模式:这样可以创建一个网卡,接管电脑所有网络,否则只能浏览器,或者支持代理的软件访问

    Clash 基础配置可以看: https://github.com/juzisang/Rules/blob/main/clash.yaml

    添加如下配置

    clash-config.yaml

    # 添加节点
    proxies:
      - {
          name: HomeProxy,
          server: 127.0.0.1,
          port: 10080,
          type: socks5,
          username: xxx,
          password: xxx,
        }
    
    ...
    
    proxy-groups:
      - name: 🏠 家庭网络
        type: select
        proxies:
          - HomeProxy
    
    ...
    
    rules:
      # 自定义规则
      - IP-CIDR,192.168.5.0/24,🏠 家庭网络
    

    3.1 解决公司内部 DNS 问题

    公司有很多内部服务,不对外开放,一般都是内部有一个私有 DNS 服务器,来负责这些内部服务的域名解析,但是 clash 接管整机网络之后,DNS 也会接管,会导致这些服务找不到 ip

    添加如下配置

    clash-config.yaml

    dns:
      enable: true
      listen: :1053
      enhanced-mode: fake-ip
      fake-ip-filter:
        - "*"
        - "+.lan"
        - "+.local"
      default-nameserver:
        - 223.5.5.5
        - 119.29.29.29
        - 114.114.114.114
      proxy-server-nameserver:
        - https://doh.pub/dns-query
      nameserver:
        # 这里填公司的私有 DNS 地址
        - 192.168.x.x
        - 192.168.x.x
      nameserver-policy:
        # 被墙的域名才走这个解析
        "geosite:gfw":
          - "tls://8.8.4.4#dns"
          - "tls://1.0.0.1#dns"
    
    6 条回复    2024-04-12 13:05:06 +08:00
    bawanag
        1
    bawanag  
       20 天前
    大佬牛的,公网 ip 搬家的话要求一起迁过来就行了把,直接疯狂申诉要求上到工信部,尝试过了可以迁过来
    juzisang
        2
    juzisang  
    OP
       20 天前
    @bawanag #1 我看到过别人也是这么说,疯狂投诉。打了 3-4 个电信客服都说没办法给,就我自己一个人用,懒得弄了。正好把每月宽带资费下降点。
    juzisang
        3
    juzisang  
    OP
       20 天前
    有公网 IP 的也可以用这个方案,去掉 Frp 那步就行,直接开个 socks 服务,搭配 clash 体验很完美,和家里局域网一模一样
    bawanag
        4
    bawanag  
       20 天前   ❤️ 1
    我申请的公网 ip 当时是免费的,我的话术大概是这样你可以参考一下:
    之前我的每个月价格是 1XX, 带 XXXX 上行和 XXX 下行带宽以及公网 ip ,现在迁过来你们要求我提升价格到 XXX 然后还把公网 ip 禁了,就是霸王条款,请找你们主管来,不行我举报工信部,举报恶意抬价。

    可以参考一下哈,之前也是打死也不给办,后来也是对线了很久才拿下来。
    SmiteChow
        5
    SmiteChow  
       19 天前
    自己用推荐 cloudflare tunnel ,还省云服务器费用,公用推荐 ddns ,同样省云服务器费用。
    yeyang5211
        6
    yeyang5211  
       19 天前
    我搬进去的公寓可以 upnp 打洞 , 可以试试 zeroTier 运气好能 p2p
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2325 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 12:02 · PVG 20:02 · LAX 05:02 · JFK 08:02
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.