小公司灵活的内外网访问架构

为了保障网络的稳定性、安全性以及灵活访问内外网的能力,我们设计了一套适用于小型办公场景的高性价比网络架构,具备以下特性:

  • 高速光纤上网;
  • 分流访问国内与国际服务;
  • 局域网内部可控与隔离;
  • 支持远程 VPN 连接;
  • 网络设备开源可控、便于后期扩展。

网络拓扑图


光猫配置(桥接模式)

目的:

让光猫“透明”接入,只做调制解调,拨号和路由功能全交给软路由。

操作示例:

  • 登录光猫管理界面(一般是 192.168.1.1)

  • 找到网络设置 > WAN口设置

  • 选择 桥接模式(Bridge Mode)

  • 关闭光猫自带的路由、DHCP等功能

  • 保存并重启


软路由配置(以 OpenWRT 为例)

软路由是核心设备,完成拨号上网、VPN客户端、策略路由和内网管理。

WAN 拨号上网

软路由通过 OpenWRT 的 WAN 接口拨号上网(如 PPPoE),确认 网络 > 接口 > WAN 是在线状态,并能正常上网。

设置LAN1/LAN2接口

LAN1(国内)设置 名称:lan1

接口设备:br-lan1(或 eth1,根据你的物理口绑定)

协议:静态地址

IP地址:例如 192.168.10.1/24

LAN2(国外)设置 名称:lan2

接口设备:br-lan2(或 eth2)

协议:静态地址

IP地址:例如 192.168.20.1/24

⚠️ 确保物理接口(网络 > 接口 > 设备)将 LAN1 接到 port1,LAN2 接到 port2(物理网口绑定)。

配置sing-box

安装工具

opkg update
opkg install kmod-tun ip-full iptables-mod-tproxy iptables-mod-extra

/etc/sing-box/config.json,配置

{
  "log": {
    "level": "info"
  },
  "inbounds": [
    {
      "type": "tun",
      "interface_name": "tun-sbox",
      "inet4_address": "172.19.0.1/30",
      "stack": "system",
      "mtu": 9000,
      "auto_route": false,
      "strict_route": true
    }
  ],
  "outbounds": [
    {
      "type": "hysteria2",
      "server": "your.server.com:443",
      "auth_str": "your-password",
      "up_mbps": 100,
      "down_mbps": 100,
      "tls": {
        "enabled": true,
        "insecure": false
      },
      "tag": "proxy"
    },
    {
      "type": "direct",
      "tag": "direct"
    },
    {
      "type": "block",
      "tag": "block"
    }
  ],
  "route": {
    "rules": [
      {
        "source_ip_cidr": ["192.168.20.0/24"],
        "outbound": "proxy"
      },
      {
        "source_ip_cidr": ["192.168.10.0/24"],
        "outbound": "direct"
      }
    ]
  },
  "dns": {
    "servers": [
      {
        "tag": "local",
        "address": "223.5.5.5",
        "detour": "direct"
      },
      {
        "tag": "remote",
        "address": "1.1.1.1",
        "detour": "proxy"
      }
    ],
    "rules": [
      {
        "source_ip_cidr": ["192.168.10.0/24"],
        "server": "local"
      },
      {
        "source_ip_cidr": ["192.168.20.0/24"],
        "server": "remote"
      }
    ]
  }
}

启动 sing-box

sing-box run -c /etc/sing-box/config.json

配置策略路由(让 LAN2 流量走 tun) 编辑 /etc/iproute2/rt_tables:

100 lan2proxy

设置规则(注意 tun-sbox 是 sing-box 的 tun 接口)

ip rule add from 192.168.20.0/24 table lan2proxy
ip route add default dev tun-sbox table lan2proxy

可以加进 /etc/rc.local 以保证开机自动执行。

配置防火墙规则(NAT 给 tun) 编辑 /etc/firewall.user 末尾加:

# NAT 转发至 sing-box tun 接口
iptables -t nat -A POSTROUTING -o tun-sbox -j MASQUERADE

# 转发 LAN2 → tun
iptables -A FORWARD -i br-lan2 -o tun-sbox -j ACCEPT
iptables -A FORWARD -i tun-sbox -o br-lan2 -j ACCEPT

然后重启防火墙:

/etc/init.d/firewall restart