Skip to content

Commit 5cf3f97

Browse files
committed
ops/net/intranet: add wg on ifupdown
1 parent 93ef77d commit 5cf3f97

File tree

1 file changed

+30
-8
lines changed

1 file changed

+30
-8
lines changed

docs/ops/network/intranet.md

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ wg genkey | tee privatekey | wg pubkey > publickey
9191

9292
这将在当前目录下生成两个文件:`privatekey``publickey`
9393

94-
### 创建配置文件
94+
### 基于 `wg-quick` 工具设置 WireGuard 接口
9595

9696
这里以一个简单的场景为例,两台机器 A 和 B 进行组网。其中 A 有公网 IP,对应域名 `example.com`
9797

@@ -132,30 +132,52 @@ PersistentKeepalive = 25
132132

133133
配置文件需要写在 `/etc/wireguard/<配置名>.conf` 中。例如:`/etc/wireguard/wg0.conf`
134134

135-
### 启动 WireGuard 接口
135+
#### 启停 WireGuard 接口
136136

137137
使用 `wg-quick` 工具启动 WireGuard 接口:
138138

139139
```shell
140140
sudo wg-quick up wg0
141+
sudo wg-quick down wg0
141142
```
142143

143144
其中 `wg0` 是配置文件的名称,不包括 `.conf` 后缀。
144145

145-
### 检查接口状态
146+
也可以基于 systemd 对 `wg-quick` 工具生成的接口进行管理:
146147

147-
可以使用 `wg` 命令查看当前的 WireGuard 状态:
148+
```shell
149+
sudo systemctl start wg-quick@wg0
150+
sudo systemctl stop wg-quick@wg0
151+
```
152+
153+
### 基于 interface 设置 WireGuard 接口
154+
155+
场景同上,B 的配置如下:
148156

149157
```shell
150-
sudo wg
158+
auto wg0
159+
iface wg0 inet static
160+
address 10.0.0.4
161+
netmask 255.255.255.255
162+
pointopoint 10.0.0.1
163+
pre-up ip link add dev $IFACE type wireguard
164+
post-down ip link del dev $IFACE
165+
up wg set $IFACE private-key <B 的私钥> peer <A 的公钥> endpoint example.com:51820 allowed-ips 0.0.0.0/0,::/0
151166
```
152167

153-
### 停止 WireGuard 接口
168+
使用传统的 `ifupdown` 工具即可启停 WireGuard 接口
154169

155-
当不再需要时,可以使用以下命令停止接口:
170+
```shell
171+
sudo ifup wg0
172+
sudo ifdown wg0
173+
```
174+
175+
### 检查接口状态
176+
177+
可以使用 `wg` 命令查看当前的 WireGuard 状态:
156178

157179
```shell
158-
sudo wg-quick down wg0
180+
sudo wg
159181
```
160182

161183
## Headscale

0 commit comments

Comments
 (0)