feat(script): add vpn-overlay config
This commit is contained in:
parent
aedee35c2f
commit
be60f3e617
61
config/sites.yaml
Normal file
61
config/sites.yaml
Normal file
@ -0,0 +1,61 @@
|
||||
# 基础网络参数
|
||||
wg_network: 10.100.0.0/24
|
||||
bridge_network: 172.16.0.0/16
|
||||
vxlan_id: 100
|
||||
hub_port: 51820
|
||||
|
||||
# 全局功能开关
|
||||
features:
|
||||
enable_gretap: true # 是否开启 gretap 桥接(站点接入 Hub)
|
||||
enable_vxlan_between_hubs: true # 是否开启 Hub 之间的 VXLAN Mesh
|
||||
enable_vless: true # 是否通过 VLESS 中转 WG 流量
|
||||
enable_multi_hub: true # 是否支持多 Hub 架构(false 则为单 Hub star 架构)
|
||||
only_wireguard: false # 若为 true,仅使用 WireGuard 点对点,忽略 gretap/vxlan
|
||||
|
||||
# WireGuard Hub 节点配置
|
||||
hubs:
|
||||
- name: hub1
|
||||
wg_ip: 10.100.0.1
|
||||
br_ip: 172.16.0.1
|
||||
public_ip: hub1.example.com
|
||||
|
||||
- name: hub2
|
||||
wg_ip: 10.100.1.1
|
||||
br_ip: 172.16.1.1
|
||||
public_ip: hub2.example.com
|
||||
|
||||
# 各个站点定义
|
||||
sites:
|
||||
- name: site_a
|
||||
wg_ip: 10.100.0.2
|
||||
br_ip: 172.16.0.2
|
||||
hub: hub1
|
||||
public_ip: a.example.com
|
||||
vless:
|
||||
enabled: true
|
||||
endpoint: vless-a.example.com
|
||||
uuid: "11111111-1111-1111-1111-111111111111"
|
||||
transport: ws
|
||||
tls: true
|
||||
path: /wg
|
||||
|
||||
- name: site_b
|
||||
wg_ip: 10.100.0.3
|
||||
br_ip: 172.16.0.3
|
||||
hub: hub1
|
||||
public_ip: b.example.com
|
||||
vless:
|
||||
enabled: false # 此节点不通过 VLESS,直接访问 Hub
|
||||
|
||||
- name: site_c
|
||||
wg_ip: 10.100.1.2
|
||||
br_ip: 172.16.1.2
|
||||
hub: hub2
|
||||
public_ip: c.example.com
|
||||
vless:
|
||||
enabled: true
|
||||
endpoint: vless-c.example.com
|
||||
uuid: "33333333-3333-3333-3333-333333333333"
|
||||
transport: ws
|
||||
tls: true
|
||||
path: /xray
|
||||
158
vpn-overlay/README.md
Normal file
158
vpn-overlay/README.md
Normal file
@ -0,0 +1,158 @@
|
||||
# VPN Overlay 文档
|
||||
|
||||
本项目通过 **WireGuard + VLESS + gretap/VXLAN** 构建跨云、跨平台的大二层互联网络,兼顾穿透、防火墙规避、性能与扩展性。
|
||||
|
||||
---
|
||||
|
||||
## 一、组网概述:核心协议与封装层级
|
||||
|
||||
### 1. WireGuard (WG)
|
||||
- 类型:L3 VPN(UDP 点对点随身障碍线)
|
||||
- 用途:形成低负载加密通道
|
||||
|
||||
### 2. VLESS + XTLS
|
||||
- 类型:TLS/gRPC 路由封装协议
|
||||
- 用途:作为 WireGuard 流量的带容中转
|
||||
|
||||
### 3. gretap over WireGuard
|
||||
- 类型:L2 over L3 over UDP
|
||||
- 用途:支持二层网络,包括 ARP/广播/DHCP
|
||||
|
||||
### 4. VXLAN over WireGuard
|
||||
- 类型:L2 over UDP
|
||||
- 用途:适合多 Hub 分区组网和广播
|
||||
|
||||
---
|
||||
|
||||
## 二、性能、效率、成本、场景对比
|
||||
|
||||
| 对比项 | gretap over WG | VXLAN over WG |
|
||||
|--------|----------------|----------------|
|
||||
| 封装协议 | GRE (L2 over IP) | VXLAN (L2 over UDP) |
|
||||
| 架构 | 点对点 | 多点(支持组播) |
|
||||
| 广播能力 | 完整 L2 广播 | 支持 VXLAN 组播 |
|
||||
| WG 使用 | gretap 用于 local/remote | VXLAN dev 发包 |
|
||||
| 多 Hub 扩展 | 差 | 强(VXLAN ID + 组播) |
|
||||
| 效率 | 高(原生内核支持) | 略低(UDP 重封) |
|
||||
| 云平台兼容 | 需隔缘 GRE | 要求放行 UDP 4789 |
|
||||
| MTU | 推荐 1400-1420 | 同上 |
|
||||
| 平台 | Linux only | 支持 K8s/OpenStack/Linux |
|
||||
|
||||
---
|
||||
|
||||
## 三、示意结构
|
||||
|
||||
### 基本层级
|
||||
|
||||
```
|
||||
[站点主机]
|
||||
└─ gretap
|
||||
└─ br0
|
||||
└─ wg0 → XTLS/VLESS 客户端
|
||||
→ 网络
|
||||
→ VLESS 服务端
|
||||
→ WireGuard Hub
|
||||
```
|
||||
|
||||
### Overlay 网络
|
||||
|
||||
```
|
||||
WG Layer3 网段: 10.100.0.0/24
|
||||
SiteA.wg0: 10.100.0.2 → WG-Hub: 10.100.0.1 → SiteB.wg0: 10.100.0.3
|
||||
|
||||
L2 Bridge br0: 172.16.0.0/16
|
||||
SiteA.br0: 172.16.1.1
|
||||
SiteB.br0: 172.16.2.1
|
||||
```
|
||||
|
||||
### 混合组网 (VXLAN + gretap)
|
||||
|
||||
```
|
||||
WG-Hub-1 === VXLAN === WG-Hub-2
|
||||
| |
|
||||
Site A Site B
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 四、配置开关说明 & 自动化逻辑
|
||||
|
||||
| 开关 | 默认 | 说明 |
|
||||
|------|------|------|
|
||||
| enable_gretap | true | 启用站点到 Hub 的 gretap 连接 |
|
||||
| enable_vxlan_between_hubs | true | 启用 Hub 间 VXLAN 桥接 |
|
||||
| enable_vless | true | 站点通过 VLESS 转发 WG 流量 |
|
||||
| enable_multi_hub | true | 启用多 Hub 组网 |
|
||||
| only_wireguard | false | 禁用 gretap/VXLAN,仅使用 WG |
|
||||
|
||||
**自动化逻辑**
|
||||
- 如果 vless.enabled: true → 生成 `xray-client.json` + 修改 wg0 endpoint
|
||||
- gretap 启用 → 生成 br0 框架
|
||||
- vxlan 启用 → 生成 vxlan100 和 bridge fdb mapping
|
||||
- only_wireguard = true → 不生成 gretap/VXLAN 结构
|
||||
|
||||
---
|
||||
|
||||
## 五、VXLAN 多 Hub 实现 (bridge fdb broadcast)
|
||||
|
||||
```bash
|
||||
ip link add vxlan100 type vxlan id 100 dev wg0 dstport 4789 group 239.1.1.100 ttl 10
|
||||
|
||||
bridge fdb add 00:00:00:00:00:00 dev vxlan100 dst 10.100.1.1
|
||||
bridge fdb add 00:00:00:00:00:00 dev vxlan100 dst 10.100.2.1
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 六、组网演进实践
|
||||
|
||||
| 阶段 | 架构 | 开关 | 场景 |
|
||||
|------|--------|----------------|------|
|
||||
| 1. P2P | 单点对 | only_wireguard: true | WG 连接测试 |
|
||||
| 2. Site2Site | 多站 | enable_gretap: true | L2 互联 |
|
||||
| 3. Net2Net | 多 LAN 桥接 | enable_gretap + br0 | 应用组织 |
|
||||
| 4. Single Hub | 中心 Hub | enable_multi_hub: true | 合约管理 |
|
||||
| 5. Double Hub | 双中心 | enable_vxlan_between_hubs: true | 多地区融合 |
|
||||
| 6. Multi Hub | 多中心 | 全部开 | 大型实施 |
|
||||
|
||||
### Step-by-Step
|
||||
|
||||
#### 第一步: P2P 模型
|
||||
- 启用 WG 通信
|
||||
- 配置 /etc/wireguard/wg0.conf
|
||||
|
||||
#### 第二步: 二站 L2 通
|
||||
- 启用 gretap
|
||||
- 框架 br0 + 连接 gretap0
|
||||
|
||||
#### 第三步: Net2Net
|
||||
- 多个 LAN 通过 br0 带入 gretap 框架
|
||||
|
||||
#### 第四步: Signal Hub
|
||||
- 各站点 gretap 连接 Hub
|
||||
- 如有需要同时启用 VLESS
|
||||
|
||||
#### 第五步: Double Hub
|
||||
- Hub 间通过 VXLAN 结合 WG 融合
|
||||
- 用 bridge fdb 构建组播 VXLAN
|
||||
|
||||
#### 第六步: Multi Hub 应用
|
||||
- 每个 Hub 都搭建 vxlan100 和 br0
|
||||
- 站点自选最近 Hub
|
||||
- 支持任意云平台
|
||||
|
||||
---
|
||||
|
||||
## 七、扩展建议
|
||||
|
||||
| 类型 | 内容 |
|
||||
|------|------|
|
||||
| 自动部署 | generate_all.sh 一键生成配置 |
|
||||
| YAML 配置 | 集中 config/sites.yaml |
|
||||
| 多平台 | 根据 uname 选择 GRE/VXLAN |
|
||||
| 灾处备份 | 多 Hub 配置切换 |
|
||||
| 状态监控 | Prometheus 搭配 WG Exporter |
|
||||
|
||||
---
|
||||
|
||||
> 本项目支持定制化配置,合适各类场景,有关 YAML 配置、服务启动脚本、应用调试相关内容,请连续跟踪项目文档和 config 文件夹。
|
||||
0
vpn-overlay/config/sites.yaml
Normal file
0
vpn-overlay/config/sites.yaml
Normal file
12
vpn-overlay/gretap/setup_hub_gretap.sh
Normal file
12
vpn-overlay/gretap/setup_hub_gretap.sh
Normal file
@ -0,0 +1,12 @@
|
||||
# 添加 br0 和多个 gretap 接口(每个分支一个)
|
||||
ip link add gretap_a type gretap local 10.100.0.1 remote 10.100.0.2
|
||||
ip link add gretap_b type gretap local 10.100.0.1 remote 10.100.0.3
|
||||
ip link add gretap_c type gretap local 10.100.0.1 remote 10.100.0.4
|
||||
|
||||
ip link add br0 type bridge
|
||||
brctl addif br0 gretap_a
|
||||
brctl addif br0 gretap_b
|
||||
brctl addif br0 gretap_c
|
||||
ip addr add 172.16.0.1/16 dev br0
|
||||
ip link set br0 up
|
||||
|
||||
21
vpn-overlay/gretap/setup_site_gretap.sh
Normal file
21
vpn-overlay/gretap/setup_site_gretap.sh
Normal file
@ -0,0 +1,21 @@
|
||||
|
||||
#!/bin/bash
|
||||
|
||||
# 启动 WireGuard
|
||||
wg-quick up wg0
|
||||
|
||||
# gretap to Site A
|
||||
ip link add gretap_a type gretap local 10.100.0.1 remote 10.100.0.2
|
||||
ip link set gretap_a up
|
||||
|
||||
# gretap to Site B
|
||||
ip link add gretap_b type gretap local 10.100.0.1 remote 10.100.0.3
|
||||
ip link set gretap_b up
|
||||
|
||||
# 创建桥接
|
||||
ip link add br0 type bridge
|
||||
ip link set gretap_a master br0
|
||||
ip link set gretap_b master br0
|
||||
ip addr add 172.16.0.1/16 dev br0
|
||||
ip link set br0 up
|
||||
|
||||
0
vpn-overlay/templates/generate_all.sh
Normal file
0
vpn-overlay/templates/generate_all.sh
Normal file
19
vpn-overlay/topology/l2_topology.mmd
Normal file
19
vpn-overlay/topology/l2_topology.mmd
Normal file
@ -0,0 +1,19 @@
|
||||
|
||||
|
||||
graph TD
|
||||
subgraph Hub1
|
||||
H1[Hub1]
|
||||
A[Site A]
|
||||
B[Site B]
|
||||
H1 --> A
|
||||
H1 --> B
|
||||
end
|
||||
|
||||
subgraph Hub2
|
||||
H2[Hub2]
|
||||
C[Site C]
|
||||
H2 --> C
|
||||
end
|
||||
|
||||
H1 <--> H2
|
||||
|
||||
0
vpn-overlay/topology/l2_topology.vsdx
Normal file
0
vpn-overlay/topology/l2_topology.vsdx
Normal file
28
vpn-overlay/vxlan/setup_hub_vxlan.sh
Normal file
28
vpn-overlay/vxlan/setup_hub_vxlan.sh
Normal file
@ -0,0 +1,28 @@
|
||||
#!/bin/bash
|
||||
|
||||
VXLAN_ID=100
|
||||
VXLAN_DEV=vxlan100
|
||||
WG_DEV=wg0
|
||||
BRIDGE=br0
|
||||
|
||||
# 本地 WG IP
|
||||
LOCAL_IP=10.100.0.1
|
||||
|
||||
# 远端 Hub WG IPs(去掉本地)
|
||||
PEERS=(
|
||||
10.100.1.1
|
||||
10.100.2.1
|
||||
)
|
||||
|
||||
# 创建 VXLAN
|
||||
ip link add $VXLAN_DEV type vxlan id $VXLAN_ID dev $WG_DEV dstport 4789 local $LOCAL_IP
|
||||
ip link set $VXLAN_DEV up
|
||||
|
||||
# 添加静态 FDB 映射
|
||||
for PEER_IP in "${PEERS[@]}"; do
|
||||
bridge fdb add 00:00:00:00:00:00 dev $VXLAN_DEV dst $PEER_IP
|
||||
done
|
||||
|
||||
# 添加进 br0
|
||||
brctl addif $BRIDGE $VXLAN_DEV
|
||||
|
||||
19
vpn-overlay/wireguard/hub1_wg0.conf
Normal file
19
vpn-overlay/wireguard/hub1_wg0.conf
Normal file
@ -0,0 +1,19 @@
|
||||
# wg0.conf
|
||||
[Interface]
|
||||
PrivateKey = <hub_priv>
|
||||
Address = 10.100.0.1/24
|
||||
ListenPort = 51820
|
||||
|
||||
# Site A
|
||||
[Peer]
|
||||
PublicKey = <a_pub>
|
||||
AllowedIPs = 10.100.0.2/32
|
||||
|
||||
# Site B
|
||||
[Peer]
|
||||
PublicKey = <b_pub>
|
||||
AllowedIPs = 10.100.0.3/32
|
||||
|
||||
# Site C
|
||||
...
|
||||
|
||||
10
vpn-overlay/wireguard/site_a_wg0.conf
Normal file
10
vpn-overlay/wireguard/site_a_wg0.conf
Normal file
@ -0,0 +1,10 @@
|
||||
# wg0.conf
|
||||
[Interface]
|
||||
PrivateKey = <a_priv>
|
||||
Address = 10.100.0.2/24
|
||||
|
||||
[Peer]
|
||||
PublicKey = <hub_pub>
|
||||
AllowedIPs = 10.100.0.1/32
|
||||
Endpoint = <hub_public_ip>:51820
|
||||
PersistentKeepalive = 25
|
||||
15
vpn-overlay/xray/GRPC-XTLS-client.json
Normal file
15
vpn-overlay/xray/GRPC-XTLS-client.json
Normal file
@ -0,0 +1,15 @@
|
||||
"inbounds": [{
|
||||
"port": 443,
|
||||
"protocol": "vless",
|
||||
"settings": {
|
||||
"clients": [...],
|
||||
"decryption": "none"
|
||||
},
|
||||
"streamSettings": {
|
||||
"network": "grpc",
|
||||
"grpcSettings": {
|
||||
"serviceName": "vpn"
|
||||
},
|
||||
"security": "xtls"
|
||||
}
|
||||
}]
|
||||
15
vpn-overlay/xray/TCP-XTLS-client.json
Normal file
15
vpn-overlay/xray/TCP-XTLS-client.json
Normal file
@ -0,0 +1,15 @@
|
||||
"inbounds": [{
|
||||
"port": 443,
|
||||
"protocol": "vless",
|
||||
"settings": {
|
||||
"clients": [...],
|
||||
"decryption": "none"
|
||||
},
|
||||
"streamSettings": {
|
||||
"network": "tcp",
|
||||
"security": "xtls",
|
||||
"xtlsSettings": {
|
||||
"alpn": ["h2", "http/1.1"]
|
||||
}
|
||||
}
|
||||
}]
|
||||
Loading…
Reference in New Issue
Block a user