Proton VPN 主页

如何使用 WireGuard 在 MikroTik 路由器上设置 Proton VPN

阅读
1 分钟
类别
路由器

您可以在 MikroTik 路由器上设置 Proton VPN,让所有通过它连接互联网的设备都受到 Proton VPN 的保护。

在本指南中,我们将向您展示如何在运行 RouterOS 7 的 MicroTik 路由器上使用 WireGuard VPN 协议来完成此操作。这需要一个 Proton VPN 帐户

如何在 MikroTik 路由器上设置 Proton VPN WireGuard®(更新)

1. 下载 WireGuard 配置文件

使用任意文本编辑器打开该文件。

了解如何从 Proton VPN 下载 WireGuard 配置文件

请注意,您不能使用已保存的配置文件。Proton VPN 从不存储您的私钥,因此已保存的配置文件中没有私钥。您必须创建并下载新的配置文件。

2. 打开 MikroTik 配置面板

为此,请打开命令行(在 Linux 和 macOS 上使用 Terminal,在 Windows 上使用 PowerShell)并输入:

ssh user@192.168.88.1

详细了解如何在 MikroTik 上使用命令行(新窗口)

3. 创建新的 WireGuard 接口

在命令行中输入以下文本并轻点 。要找到您的私钥,请在前文下载的 WireGuard 配置文件中查找以 PrivateKey= 开头的行。

/interface wireguard
add listen-port=13231 mtu=1420 name=wireguard-inet private-key=”your private key”

接下来的所有步骤都需要您在命令行中输入命令。

4. 为刚创建的接口添加 IP 地址:

/ip address
add address=10.2.0.2/30 interface=wireguard-inet network=10.2.0.0

5. 将 WireGuard 服务器添加为对等端

添加 WireGuard 配置文件中的端点地址、端点端口和公钥。查找以 PublicKey= 和 Endpoint= 开头的行。

例如,如果配置中显示 Endpoint=103.107.197.2:51820,则输入 endpoint-address=103.107.197.2 和 endpoint-port=51820

/interface wireguard peers
add allowed-address=0.0.0.0/0 endpoint-address=x.x.x.x endpoint-port=xxxxx interface=wireguard-inet persistent-keepalive=25s public-key="your public key"

6. 为该接口启用 masquerade(伪装)

注意:此设置假设您使用的是 MikroTik 默认的本地网络地址。如果您已更改此地址,请改用该地址作为 scr-address= 的值。

/ip firewall nat
add action=masquerade chain=srcnat out-interface=wireguard-inet src-address=192.168.88.0/24

7. 将所有互联网流量重定向至 WireGuard

/ip route
add disabled=no distance=1 dst-address=0.0.0.0/1 gateway=10.2.0.1 pref-src="" routing-table=main scope=30 suppress-hw-offload=no target-scope=10
add disabled=no distance=1 dst-address=128.0.0.0/1 gateway=10.2.0.1 pref-src="" routing-table=main scope=30 suppress-hw-offload=no target-scope=10

8. 配置 DNS 设置

/ip dns
set servers=10.2.0.1
/ip dhcp-client
set 0 use-peer-dns=no

9. 通过主运营商的网关转发 WireGuard IP 地址

将 x.x.x.x 替换为配置文件中的 端点地址(Endpoint=)。

/ip route
add disabled=no dst-address=x.x.x.x/32 gateway=[/ip dhcp-client get [find interface=ether1] gateway] routing-table=main suppress-hw-offload=no

如果这不起作用,您需要将 gateway=[/ip dhcp-client get [find interface=ether1] gateway] 替换为 gateway=x.x.x.x,其中 x.x.x.x 是您自己的互联网网关地址。您的互联网服务提供商(ISP)应该能够提供此地址。

10. 重启路由器

大功告成!您的路由器现在应该会用 Proton VPN 保护其提供的所有互联网连接。