forked from lanthora/candy
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
58 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
# 多局域网互联 | ||
|
||
## 需求 | ||
|
||
在多地有多个地址相互不冲突的局域网时,希望能够让本局域网内的设备通过其他局域网的地址直接访问对方的设备,而不必在每台设备上都部署 Candy 客户端. | ||
|
||
## 示例 | ||
|
||
此处假设你已经能够在网关(Gateway)上部署 Candy 并成功分配了虚拟地址(例如:10.0.0.1).此处的网关可以是路由器,也可以是局域网中任意一台 Linux 系统. | ||
|
||
| LAN | A | B | C | | ||
| :------ | :------------- | :------------- | :------------- | | ||
| Network | 192.168.1.0/24 | 192.168.2.0/24 | 192.168.3.0/24 | | ||
| Gateway | 192.168.1.1 | 192.168.2.1 | 192.168.3.1 | | ||
| Candy | 10.0.0.1 | 10.0.0.2 | 10.0.0.3 | | ||
|
||
当 `192.168.1.x` 访问 `192.168.2.x` 时,希望流量可以通过以下方式送达 | ||
|
||
```txt | ||
192.168.1.x => 10.0.0.1 => 10.0.0.2 => 192.168.2.x | ||
``` | ||
|
||
接下来以这条链路为例解释配置过程.其他链路配置方法相同. | ||
|
||
### 在 Candy 配置服务端路由 | ||
|
||
在 Candy 服务端上增加以下路由配置,此配置会修改网关上的系统路由. | ||
|
||
| Device | Device Mask | Dest Net | Dest Mask | Gateway | | ||
| :------- | :-------------- | :---------- | :------------ | :------- | | ||
| 10.0.0.1 | 255.255.255.255 | 192.168.2.0 | 255.255.255.0 | 10.0.0.2 | | ||
|
||
添加系统路由后, `192.168.1.1` 的 Candy 客户端将能收到发往 `192.168.2.x` 的 IP 报文. Candy 负责将本报文转发到 `192.168.2.1` | ||
|
||
### 流量转发到网关 | ||
|
||
如果网关是路由器,不需要任何操作,流量就应该能够进入网关. | ||
|
||
否则需要在非网关设备上配置流量转发到网关的路由. | ||
|
||
- 目的网络: 192.168.2.0/24 | ||
- 网关: 192.168.1.1 | ||
|
||
### 允许网关转发流量 | ||
|
||
如果你的网关是路由器,应该能够轻易的配置出允许转发.否则需要手动添加转发相关的配置. | ||
|
||
开启内核流量转发功能 | ||
|
||
```bash | ||
sysctl -w net.ipv4.ip_forward=1 | ||
``` | ||
|
||
判断流量进入网关的网口,这里假设是 `ethX`, 并假设 candy 使用的网口名是 `candy-gw`. | ||
|
||
```bash | ||
iptables -t nat -A POSTROUTING -o candy-gw -j MASQUERADE | ||
``` |