File tree Expand file tree Collapse file tree 1 file changed +30
-8
lines changed
Expand file tree Collapse file tree 1 file changed +30
-8
lines changed Original file line number Diff line number Diff 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
140140sudo 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
You can’t perform that action at this time.
0 commit comments