【问题标题】:WireGuard: How to push routes and dhcp options to clients from server? [closed]WireGuard:如何从服务器向客户端推送路由和 dhcp 选项? [关闭]
【发布时间】:2019-07-13 13:07:27
【问题描述】:

WireGuard 是否支持 VPN 服务器向其客户端推送路由和 DHCP 选项的方式,就像 OpenVPN 所做的那样:

push "route 10.0.2.0 255.255.255.0 " 

push "dhcp-option DNS 10.66.0.4"

我有 100 多个客户端动态设置它们与 VPN 服务器的 VPN 连接,我希望在它们连接到 VPN 服务器时安装这些路由和选项。

【问题讨论】:

标签: vpn openvpn wireguard


【解决方案1】:

对于当前版本,这是不可能的。 IPSec 和 OpenVPN 有数千行代码来处理路由策略(至少是 IPSec)以及 IP 地址的配置。 Wireguard 希望这些在每个文件中都被硬编码,至少目前是这样。

请注意,拥有点对点接口比 OpenVPN 的多种桥接模式要好,但无法在内核模块内部配置接口。 IE。没有第 2 层代码。有点遗憾,因为其余的都很干净。

【讨论】:

    【解决方案2】:

    路由甚至拆分隧道是通过在客户端配置中设置Allowed IPs 参数来完成的!

    客户端配置

    [Interface]
    # client001 #
    PrivateKey = <private key of client>
    Address = 100.64.0.100/32
    DNS = 100.64.0.1
    
    [Peer]
    PublicKey = <public key of server>
    PresharedKey = <preshared key for client>
    AllowedIPs = 100.64.0.0/10, 192.168.178.0/24
    Endpoint = <your-ip-or-fqdn.to.connect>:<port>
    PersistentKeepalive = 25
    

    服务器配置

    [Interface]
    Address = 100.64.0.1/10
    SaveConfig = true
    ListenPort = 51820
    PrivateKey = <private key of server>
    
    [Peer]
    PublicKey = <public key of client>
    PresharedKey = <preshared key for client>
    AllowedIPs = 100.64.0.100/32
    

    在这种情况下,客户端 AllowedIPs = 100.64.0.0/10, 192.168.178.0/24 的配置在客户端上设置路由,以将 100.64.0.0/10 和 192.168.178.0/24 的所有内容发送到 wireguard 隧道,但没有其他内容。 (在 WireGuard 服务器上也激活了 IP 转发和伪装。)

    DNS = 100.64.0.1 参数告诉客户端使用100.64.0.1(在我的例子中是 WireGuard 服务器)作为 DNS 服务器。即使 DNS 在 WireGuard-Server 本身上,互联网流量仍然是直接路由的,只有 DNS 是由我的自定义 DNS 完成的。

    【讨论】:

    • 但正如我所提到的,我有 100 多个客户端动态设置其与 VPN 服务器的 VPN 连接,我希望在客户端连接到 VPN 服务器时推送/安装这些路由和选项。我不想去每个客户端手动设置其 AllowedIP。
    • WireGuard 正在大力开发中。 Afaik 他们正在开发一个名为“wg-dynamic”的功能,可以解决您的问题。目前手册页 (man wg) 声明:AllowedIPs — a comma-separated list of IP (v4 or v6) addresses with CIDR masks from which incoming traffic for this peer is allowed and to which outgoing traffic for this peer is directed. The catch-all 0.0.0.0/0 may be specified for matching all IPv4 addresses, and ::/0 may be specified for matching all IPv6 addresses. May be specified multiple times.
    猜你喜欢
    • 1970-01-01
    • 2017-11-28
    • 2016-01-10
    • 2010-10-03
    • 1970-01-01
    • 1970-01-01
    • 2022-01-17
    • 2019-11-12
    • 2013-03-30
    相关资源
    最近更新 更多