Azure VPN Client - 配置可选的 DNS 和路由设置

本文可帮助你为 VPN 网关 P2S 连接配置 Azure VPN Client 的可选设置。 可以配置 DNS 后缀、自定义 DNS 服务器、自定义路由和 VPN 客户端强制隧道。

注意

Azure VPN 客户端仅支持 OpenVPN® 协议连接。

开始之前

如果尚未这样做,请确保完成以下各项:

  • 为 P2S 部署生成并下载 VPN 客户端配置文件。 请使用以下步骤:

    1. 在 Azure 门户中,转到虚拟网络网关。
    2. 单击“点到站点配置” 。
    3. 单击“下载 VPN 客户端”。
    4. 选择客户端,并填充请求的任何信息。
    5. 单击“下载”,生成 .zip 文件 。
    6. .zip 文件通常下载到 Downloads 文件夹。
  • 下载并安装 Azure VPN 客户端。 有关步骤,请参阅以下文章之一:

使用 VPN 客户端配置文件

要执行本文中的步骤,你需要修改和导入 Azure VPN 客户端配置文件。 若要使用 VPN 客户端配置文件(xml 文件),请执行以下步骤:

  1. 找到配置文件,然后使用所选的编辑器将其打开。

  2. 使用以下各部分中的示例,根据需要修改文件,然后保存所做的更改。

  3. 导入文件以配置 Azure VPN 客户端。 可使用以下方法为 Azure VPN Client 导入文件:

    • Azure VPN Client 界面:打开 Azure VPN Client,然后依次单击 + 和“导入”。 找到修改后的 xml 文件,根据需要在 Azure VPN 客户端接口中配置任何其他设置,然后单击“保存”。

    • 命令行提示:将下载的 azurevpnconfig.xml 文件添加到 %userprofile%\AppData\Local\Packages\Microsoft.AzureVpn_8wekyb3d8bbwe\LocalState 文件夹,然后运行以下命令:azurevpn -i azurevpnconfig.xml。 若要强制导入,请使用 -f 开关。

DNS

添加 DNS 后缀

若要添加 DNS 后缀,请修改下载的配置文件 XML 文件,并添加 <dnssuffixes><dnssufix></dnssufix></dnssuffixes> 标记。

<azvpnprofile>
<clientconfig>

    <dnssuffixes>
          <dnssuffix>.mycorp.com</dnssuffix>
          <dnssuffix>.xyz.com</dnssuffix>
          <dnssuffix>.etc.net</dnssuffix>
    </dnssuffixes>

</clientconfig>
</azvpnprofile>

添加自定义 DNS 服务器

若要添加自定义 DNS 服务器,请修改下载的配置文件 XML 文件,并添加 <dnsservers><dnsserver></dnsserver></dnsservers> 标记。

<azvpnprofile>
<clientconfig>

    <dnsservers>
        <dnsserver>x.x.x.x</dnsserver>
            <dnsserver>y.y.y.y</dnsserver>
    </dnsservers>

</clientconfig>
</azvpnprofile>

注意

OpenVPN Microsoft Entra 客户端使用 DNS 名称解析策略表 (NRPT) 条目,这意味着不会在 ipconfig /all 的输出下列出 DNS 服务器。 若要确认使用中的 DNS 设置,请使用 PowerShell 中的 Get-DnsClientNrptPolicy

路由

拆分隧道

默认情况下,为 VPN 客户端配置了拆分隧道。

强制隧道

可以配置强制隧道,以便将所有流量定向到 VPN 隧道。 可使用两种不同的方法配置强制隧道:播发自定义路由,或修改配置文件 XML 文件。 如果使用 Azure VPN 客户端版本 2.1900:39.0 或更高版本,则可以包含 0/0。

注意

不通过 VPN 网关提供 Internet 连接。 因此,会删除所有绑定到 Internet 的流量。

  • 播发自定义路由:可以播发自定义路由 0.0.0.0/1128.0.0.0/1。 有关详细信息,请参阅为 P2S VPN 客户端播发自定义路由

  • 配置文件 XML:可以修改下载的配置文件 XML 文件,并添加 <includeroutes><route><destination><mask></destination></mask></route></includeroutes> 标记。 请确保将版本号更新为 2。

    <azvpnprofile>
    <clientconfig>
    
      <includeroutes>
          <route>
              <destination>0.0.0.0</destination><mask>1</mask>
          </route>
          <route>
              <destination>128.0.0.0</destination><mask>1</mask>
          </route>
      </includeroutes>
    
    </clientconfig>
    </azvpnprofile>
    

注意

  • clientconfig 标记的默认状态为 <clientconfig i:nil="true" />,可根据要求对其进行修改。
  • macOS 不支持重复的 clientconfig 标记,因此请确保 XML 文件中的 clientconfig 标记没有重复。

添加自定义路由

可以添加自定义路由。 修改下载的配置文件 XML 文件,并添加 <includeroutes><route><destination><mask></destination></mask></route></includeroutes> 标记。

<azvpnprofile>
<clientconfig>

    <includeroutes>
        <route>
            <destination>x.x.x.x</destination><mask>24</mask>
        </route>
        <route>
                <destination>y.y.y.y</destination><mask>24</mask>
            </route>
    </includeroutes>

</clientconfig>
</azvpnprofile>

阻止(排除)路由

Azure VPN 客户端不支持完全阻止路由的功能。 Azure VPN 客户端不支持从本地路由表中删除路由。 相反,可以从 VPN 接口中排除路由。 修改下载的配置文件 XML 文件,并添加 <excluderoutes><route><destination><mask></destination></mask></route></excluderoutes> 标记。

<azvpnprofile>
<clientconfig>

    <excluderoutes>
        <route>
            <destination>x.x.x.x</destination><mask>24</mask>
        </route>
        <route>
            <destination>y.y.y.y</destination><mask>24</mask>
        </route>
    </excluderoutes>

</clientconfig>
</azvpnprofile>

注意

  • 若要包含/排除多个目标路由,请将每个目标地址置于单独的路由标记下(如上述示例所示),因为单个路由标记下不能有多个目标地址。
  • 如果遇到错误“目标不能为空或路由标记内有多个条目”,请检查配置文件 XML 文件,并确保 includeroutes/excluderoutes 节在一个路由标记内只有一个目标地址。

Azure VPN 客户端版本信息

有关 Azure VPN 客户端版本信息,请参阅 Azure VPN 客户端版本

后续步骤

有关 P2S VPN 的详细信息,请参阅以下文章: