Azure 虚拟网络中资源的名称解析Name resolution for resources in Azure virtual networks

可能需要允许虚拟机 (VM) 以及部署在虚拟网络中的其他资源相互通信,具体取决于如何使用 Azure 托管 IaaS、PaaS 和混合解决方案。Depending on how you use Azure to host IaaS, PaaS, and hybrid solutions, you might need to allow the virtual machines (VMs), and other resources deployed in a virtual network to communicate with each other. 尽管可以通过使用 IP 地址实现通信,但使用容易记住且不会更改的名称要简单得多。Although you can enable communication by using IP addresses, it is much simpler to use names that can be easily remembered, and do not change.

当部署在虚拟网络中的资源需要将域名解析到内部 IP 地址时,它们可以使用两种方法之一:When resources deployed in virtual networks need to resolve domain names to internal IP addresses, they can use one of two methods:

使用的名称解析类型取决于资源需要以怎样的方式进行相互通信。The type of name resolution you use depends on how your resources need to communicate with each other. 下表说明了方案和相应的名称解析解决方案:The following table illustrates scenarios and corresponding name resolution solutions:

方案Scenario 解决方案Solution 后缀Suffix
位于相同虚拟网络的 VM 或位于相同云服务的 Azure 云服务角色实例之间的名称解析。Name resolution between VMs located in the same virtual network, or Azure Cloud Services role instances in the same cloud service. Azure 提供的名称解析Azure-provided name resolution 主机名或 FQDNHostname or FQDN
位于不同虚拟网络的 VM 或位于不同云服务的角色实例之间的名称解析。Name resolution between VMs in different virtual networks or role instances in different cloud services. 客户托管的 DNS 服务器,该服务器在虚拟网络之间转发查询,并由 Azure 进行解析(DNS 代理)。Customer-managed DNS servers forwarding queries between virtual networks for resolution by Azure (DNS proxy). 请参阅使用自己的 DNS 服务器进行名称解析See Name resolution using your own DNS server. 仅 FQDNFQDN only
通过 Azure 应用服务(Web 应用、函数或自动程序)实现的名称解析:对同一虚拟网络中的角色实例或 VM 使用虚拟网络集成。Name resolution from an Azure App Service (Web App, Function, or Bot) using virtual network integration to role instances or VMs in the same virtual network. 客户托管的 DNS 服务器,该服务器在虚拟网络之间转发查询,并由 Azure 进行解析(DNS 代理)。Customer-managed DNS servers forwarding queries between virtual networks for resolution by Azure (DNS proxy). 请参阅使用自己的 DNS 服务器进行名称解析See Name resolution using your own DNS server. 仅 FQDNFQDN only
从应用服务 Web 应用到同一虚拟网络中 VM 之间的名称解析。Name resolution from App Service Web Apps to VMs in the same virtual network. 客户托管的 DNS 服务器,该服务器在虚拟网络之间转发查询,并由 Azure 进行解析(DNS 代理)。Customer-managed DNS servers forwarding queries between virtual networks for resolution by Azure (DNS proxy). 请参阅使用自己的 DNS 服务器进行名称解析See Name resolution using your own DNS server. 仅 FQDNFQDN only
从应用服务 Web 应用到不同虚拟网络中 VM 之间的名称解析。Name resolution from App Service Web Apps in one virtual network to VMs in a different virtual network. 客户托管的 DNS 服务器,该服务器在虚拟网络之间转发查询,并由 Azure 进行解析(DNS 代理)。Customer-managed DNS servers forwarding queries between virtual networks for resolution by Azure (DNS proxy). 请参阅“使用自己的 DNS 服务器进行名称解析”。See Name resolution using your own DNS server. 仅 FQDNFQDN only
解析来自 Azure 中 VM 或角色实例的本地计算机和服务名称。Resolution of on-premises computer and service names from VMs or role instances in Azure. 客户托管的 DNS 服务器(例如本地域控制器、本地只读域控制器或使用区域传送同步的 DNS 辅助服务器)。Customer-managed DNS servers (on-premises domain controller, local read-only domain controller, or a DNS secondary synced using zone transfers, for example). 请参阅使用自己的 DNS 服务器进行名称解析See Name resolution using your own DNS server. 仅 FQDNFQDN only
解析本地计算机中的 Azure 主机名。Resolution of Azure hostnames from on-premises computers. 将查询转发到相应虚拟网络中客户托管的 DNS 代理服务器,该代理服务器将查询转发到 Azure 进行解析。Forward queries to a customer-managed DNS proxy server in the corresponding virtual network, the proxy server forwards queries to Azure for resolution. 请参阅使用自己的 DNS 服务器进行名称解析See Name resolution using your own DNS server. 仅 FQDNFQDN only
针对内部 IP 的反向 DNS。Reverse DNS for internal IPs. 使用自己的 DNS 服务器的名称解析Name resolution using your own DNS server. 不适用Not applicable
位于不同云服务(而非虚拟网络)中的 VM 或角色实例之间的名称解析。Name resolution between VMs or role instances located in different cloud services, not in a virtual network. 不适用。Not applicable. 不同云服务中的 VM 和角色实例之间的连接在虚拟网络外部不受支持。Connectivity between VMs and role instances in different cloud services is not supported outside a virtual network. 不适用Not applicable

Azure 提供的名称解析Azure-provided name resolution

除公共 DNS 名称解析之外,Azure 还为驻留在相同虚拟网络或云服务中的 VM 和角色实例提供内部名称解析。Along with resolution of public DNS names, Azure provides internal name resolution for VMs and role instances that reside within the same virtual network or cloud service. 云服务中的 VM 和实例共享相同的 DNS 后缀,因此仅使用主机名便可。VMs and instances in a cloud service share the same DNS suffix, so the host name alone is sufficient. 但在使用经典部署模型部署的虚拟网络中,不同云服务具有不同的 DNS 后缀。But in virtual networks deployed using the classic deployment model, different cloud services have different DNS suffixes. 在这种情况下,需要使用 FQDN 解析不同云服务的名称。In this situation, you need the FQDN to resolve names between different cloud services. 在使用 Azure 资源管理器部署模型部署的虚拟网络内,整个虚拟网络中的 DNS 后缀一致,因此无需 FQDN。In virtual networks deployed using the Azure Resource Manager deployment model, the DNS suffix is consistent across the virtual network, so the FQDN is not needed. DNS 名称可分配给 VM 和网络接口。DNS names can be assigned to both VMs and network interfaces. 虽然 Azure 提供的名称解析不需要任何配置,但并不适合所有部署方案,参见上表详细说明。Although Azure-provided name resolution does not require any configuration, it is not the appropriate choice for all deployment scenarios, as detailed in the previous table.

Note

在使用云服务 Web 和辅助角色的情况下,还可以使用 Azure 服务管理 REST API 访问角色实例的内部 IP 地址。When using cloud services web and worker roles, you can also access the internal IP addresses of role instances using the Azure Service Management REST API. 有关详细信息,请参阅服务管理 REST API 参考For more information, see the Service Management REST API Reference. 地址基于角色名称和实例编号。The address is based on the role name and instance number.

功能Features

Azure 提供的名称解析包括以下功能:Azure-provided name resolution includes the following features:

  • 易于使用。Ease of use. 不需要任何配置。No configuration is required.
  • 高可用性。High availability. 无需创建和管理你自己的 DNS 服务器的群集。You don't need to create and manage clusters of your own DNS servers.
  • 可以结合自己的 DNS 服务器使用该服务,来解析本地主机名和 Azure 主机名。You can use the service in conjunction with your own DNS servers, to resolve both on-premises and Azure host names.
  • 可以在同一云服务中的 VM 和角色实例之间使用名称解析,无需 FQDN。You can use name resolution between VMs and role instances within the same cloud service, without the need for an FQDN.
  • 可以在使用 Azure 资源管理器部署模型的虚拟网络中的 VM 之间使用名称解析,无需 FQDN。You can use name resolution between VMs in virtual networks that use the Azure Resource Manager deployment model, without need for an FQDN. 经典部署模型中的虚拟网络需要使用 FQDN 来解析不同云服务中的名称。Virtual networks in the classic deployment model require an FQDN when you are resolving names in different cloud services.
  • 可以使用最能描述部署的主机名,而不必使用自动生成的名称。You can use host names that best describe your deployments, rather than working with auto-generated names.

注意事项Considerations

使用 Azure 提供的名称解析时要注意的问题:Points to consider when you are using Azure-provided name resolution:

  • 不能修改 Azure 创建的 DNS 后缀。The Azure-created DNS suffix cannot be modified.
  • 不能手动注册自己的记录。You cannot manually register your own records.
  • 不支持 WINS 和 NetBIOS。WINS and NetBIOS are not supported. 在 Windows 资源管理器中看不到 VM。You cannot see your VMs in Windows Explorer.
  • 主机名必须符合 DNS。Host names must be DNS-compatible. 名称只能使用 0-9、a-z 和“-”,并且不能以“-”开头或结尾。Names must use only 0-9, a-z, and '-', and cannot start or end with a '-'.
  • DNS 查询流量按照 VM 进行限制。DNS query traffic is throttled for each VM. 限制不应影响大部分应用程序。Throttling shouldn't impact most applications. 如果遵循请求限制,请确保启用客户端缓存。If request throttling is observed, ensure that client-side caching is enabled. 有关详细信息,请参阅 DNS 客户端配置For more information, see DNS client configuration.
  • 在经典部署模型中,每个虚拟网络仅注册前 180 个云服务中的 VM。Only VMs in the first 180 cloud services are registered for each virtual network in a classic deployment model. 此限制不适用于 Azure 资源管理器中的虚拟网络。This limit does not apply to virtual networks in Azure Resource Manager.
  • Azure DNS IP 地址为 168.63.129.16。The Azure DNS IP address is 168.63.129.16. 这是静态 IP 地址,不会更改。This is a static IP address and will not change.

DNS 客户端配置DNS client configuration

本部分介绍客户端缓存和客户端重试。This section covers client-side caching and client-side retries.

客户端缓存Client-side caching

不是每个 DNS 查询都需要跨网络发送。Not every DNS query needs to be sent across the network. 通过解析本地缓存中的重复性 DNS 查询,客户端缓存有助于减少延迟和提高网络信号的恢复能力。Client-side caching helps reduce latency and improve resilience to network blips, by resolving recurring DNS queries from a local cache. DNS 记录包含生存时间 (TTL) 机制,这允许缓存尽可能长时间存储记录,而不影响记录刷新。DNS records contain a time-to-live (TTL) mechanism, which allows the cache to store the record for as long as possible without impacting record freshness. 因此,客户端缓存适用于大多数情况。Thus, client-side caching is suitable for most situations.

默认 Windows DNS 客户端具有内置的 DNS 缓存。The default Windows DNS client has a DNS cache built-in. 默认情况下,某些 Linux 发行版不包括缓存。Some Linux distributions do not include caching by default. 如果没有本地缓存,请向每个 Linux VM 添加 DNS 缓存。If you find that there isn't a local cache already, add a DNS cache to each Linux VM.

有许多不同的 DNS 缓存包可用(例如 dnsmasq)。There are a number of different DNS caching packages available (such as dnsmasq). 下面介绍如何在最常见的发行版上安装 dnsmasq:Here's how to install dnsmasq on the most common distributions:

  • Ubuntu(使用 resolvconf)Ubuntu (uses resolvconf):
    • 使用 sudo apt-get install dnsmasq 安装 dnsmasq 包。Install the dnsmasq package with sudo apt-get install dnsmasq.
  • SUSE(使用 netconf)SUSE (uses netconf):
    • 使用 sudo zypper install dnsmasq 安装 dnsmasq 包。Install the dnsmasq package with sudo zypper install dnsmasq.
    • 使用 systemctl enable dnsmasq.service 启用 dnsmasq 服务。Enable the dnsmasq service with systemctl enable dnsmasq.service.
    • 使用 systemctl start dnsmasq.service 启动 dnsmasq 服务。Start the dnsmasq service with systemctl start dnsmasq.service.
    • 编辑 /etc/sysconfig/network/config 并将 NETCONFIG_DNS_FORWARDER="" 更改为 dnsmasqEdit /etc/sysconfig/network/config, and change NETCONFIG_DNS_FORWARDER="" to dnsmasq.
    • 使用 netconfig update 更新 resolv.con,将缓存设置为本地 DNS 解析程序。Update resolv.conf with netconfig update, to set the cache as the local DNS resolver.
  • CentOS(使用 NetworkManager)CentOS (uses NetworkManager):
    • 使用 sudo yum install dnsmasq 安装 dnsmasq 包。Install the dnsmasq package with sudo yum install dnsmasq.
    • 使用 systemctl enable dnsmasq.service 启用 dnsmasq 服务。Enable the dnsmasq service with systemctl enable dnsmasq.service.
    • 使用 systemctl start dnsmasq.service 启动 dnsmasq 服务。Start the dnsmasq service with systemctl start dnsmasq.service.
    • 将“prepend domain-name-servers 127.0.0.1;”添加到“/etc/dhclient-eth0.conf” 。Add prepend domain-name-servers 127.0.0.1; to /etc/dhclient-eth0.conf.
    • 使用 service network restart 重启网络服务,以将缓存设置为本地 DNS 解析程序。Restart the network service with service network restart, to set the cache as the local DNS resolver.

Note

dnsmasq 包只是适用于 Linux 的众多 DNS 缓存中的一个。The dnsmasq package is only one of many DNS caches available for Linux. 在使用之前,请检查其是否适合特定需求,且没有安装其他缓存。Before using it, check its suitability for your particular needs, and check that no other cache is installed.

客户端重试Client-side retries

DNS 主要是一个 UDP 协议。DNS is primarily a UDP protocol. 因为 UDP 协议无法保证消息传递,所以重试逻辑在DNS 协议本身中处理。Because the UDP protocol doesn't guarantee message delivery, retry logic is handled in the DNS protocol itself. 每个 DNS 客户端(操作系统)可能会表现出不同的重试逻辑,具体取决于创建者的偏好:Each DNS client (operating system) can exhibit different retry logic, depending on the creator's preference:

  • Windows 操作系统在 1 秒后重试,然后再在 2 秒后、4 秒后和额外 4 秒后再次重试。Windows operating systems retry after one second, and then again after another two seconds, four seconds, and another four seconds.
  • 默认 Linux 设置在 5 秒后重试。The default Linux setup retries after five seconds. 我们建议将重试规范更改为 5 次,每隔 1 秒一次。We recommend changing the retry specifications to five times, at one-second intervals.

使用 cat /etc/resolv.conf 检查 Linux VM 上的当前设置。Check the current settings on a Linux VM with cat /etc/resolv.conf. 查看“options” 行,例如:Look at the options line, for example:

options timeout:1 attempts:5

resolv.conf 文件通常是自动生成的,不应进行编辑。The resolv.conf file is usually auto-generated, and should not be edited. 添加 options 行的具体步骤因发行版而异:The specific steps for adding the options line vary by distribution:

  • Ubuntu(使用 resolvconf):Ubuntu (uses resolvconf):
    1. 将 options 行添加到 /etc/resolveconf/resolv.conf.d/tail 。Add the options line to /etc/resolvconf/resolv.conf.d/tail.
    2. 运行 resolvconf -u 以进行更新。Run resolvconf -u to update.
  • SUSE(使用 netconf):SUSE (uses netconf):
    1. 将“timeout:1 attempts:5”添加到“/etc/sysconfig/network/config”中的 NETCONFIG_DNS_RESOLVER_OPTIONS="" 参数 。Add timeout:1 attempts:5 to the NETCONFIG_DNS_RESOLVER_OPTIONS="" parameter in /etc/sysconfig/network/config.
    2. 运行 netconfig update 以进行更新。Run netconfig update to update.
  • CentOS(使用 NetworkManager):CentOS (uses NetworkManager):
    1. 将“echo "options timeout:1 attempts:5"”添加到“/etc/NetworkManager/dispatcher.d/11-dhclient” 。Add echo "options timeout:1 attempts:5" to /etc/NetworkManager/dispatcher.d/11-dhclient.
    2. 使用 service network restart 进行更新。Update with service network restart.

使用自己的 DNS 服务器的名称解析Name resolution that uses your own DNS server

本部分介绍 VM、角色实例以及 Web 应用。This section covers VMs, role instances, and web apps.

VM 和角色实例VMs and role instances

Azure 提供的功能可能无法满足名称解析的需求。Your name resolution needs might go beyond the features provided by Azure. 例如,可能需要使用 Windows Server Active Directory 域,解析虚拟网络之间的 DNS 名称。For example, you might need to use Microsoft Windows Server Active Directory domains, resolve DNS names between virtual networks. 考虑到这些情况,Azure 提供了使用自己的 DNS 服务器的功能。To cover these scenarios, Azure provides the ability for you to use your own DNS servers.

虚拟网络中的 DNS 服务器可将 DNS 查询转发到 Azure 的递归解析程序。DNS servers within a virtual network can forward DNS queries to the recursive resolvers in Azure. 这样,便可以解析该虚拟网络中的主机名。This enables you to resolve host names within that virtual network. 例如,在 Azure 中运行的域控制器 (DC) 可以响应自身域的 DNS 查询,而将所有其他查询转发到 Azure。For example, a domain controller (DC) running in Azure can respond to DNS queries for its domains, and forward all other queries to Azure. 转发查询,VM 就可以(通过 DC)查看本地资源以及(通过转发器)查看 Azure 提供的主机名。Forwarding queries allows VMs to see both your on-premises resources (via the DC) and Azure-provided host names (via the forwarder). 可以通过虚拟 IP 168.63.129.16 访问 Azure 中的递归解析程序。Access to the recursive resolvers in Azure is provided via the virtual IP 168.63.129.16.

DNS 转发还可用于在虚拟网络之间进行 DNS 解析,可以通过本地计算机来解析 Azure 提供的主机名。DNS forwarding also enables DNS resolution between virtual networks, and allows your on-premises machines to resolve Azure-provided host names. 若要解析 VM 的主机名,DNS 服务器 VM 必须驻留在同一虚拟网络中,并且必须配置为将主机名查询转发到 Azure。In order to resolve a VM's host name, the DNS server VM must reside in the same virtual network, and be configured to forward host name queries to Azure. 由于 DNS 后缀在每个虚拟网络中是不同的,因此可使用条件性转发规则将 DNS 查询发送到正确的虚拟网络进行解析。Because the DNS suffix is different in each virtual network, you can use conditional forwarding rules to send DNS queries to the correct virtual network for resolution. 下图显示了两个虚拟网络和一个本地网络使用本方法在虚拟网络之间进行 DNS 解析。The following image shows two virtual networks and an on-premises network doing DNS resolution between virtual networks, by using this method. DNS 转发器示例可在 Azure 快速入门模板库GitHub 中获取。An example DNS forwarder is available in the Azure Quickstart Templates gallery and GitHub.

Note

角色实例可对同一虚拟网络中的 VM 执行名称解析,A role instance can perform name resolution of VMs within the same virtual network. 方法是使用由 VM 主机名和 internal.chinacloudapp.cn DNS 后缀组成的 FQDN。It does so by using the FQDN, which consists of the VM's host name and internal.chinacloudapp.cn DNS suffix. 但是,在这种情况下,仅当角色实例在角色架构(.cscfg 文件)中定义了 VM 名称时,名称解析才会成功。However, in this case, name resolution is only successful if the role instance has the VM name defined in the Role Schema (.cscfg file). <Role name="<role-name>" vmName="<vm-name>">

需要在另一个虚拟网络中执行 VM 名称解析的角色实例(使用 internal.chinacloudapp.cn 后缀的 FQDN)必须使用本部分所述的方法(在两个虚拟网络之间进行自定义 DNS 服务器转发)。Role instances that need to perform name resolution of VMs in another virtual network (FQDN by using the internal.chinacloudapp.cn suffix) have to do so by using the method described in this section (custom DNS servers forwarding between the two virtual networks).

虚拟网络之间的 DNS 示意图

使用 Azure 提供的名称解析时,Azure 动态主机配置协议 (DHCP) 会为每个 VM 提供内部 DNS 后缀 ( .internal.chinacloudapp.cn)。When you are using Azure-provided name resolution, Azure Dynamic Host Configuration Protocol (DHCP) provides an internal DNS suffix (.internal.chinacloudapp.cn) to each VM. 此后缀可实现主机名解析,因为主机名记录位于 internal.chinacloudapp.cn 区域中。This suffix enables host name resolution because the host name records are in the internal.chinacloudapp.cn zone. 使用自己的名称解析解决方案时,不会向 VM 提供此后缀,因为该后缀会干扰其他 DNS 体系结构(例如已加入域的方案)。When you are using your own name resolution solution, this suffix is not supplied to VMs because it interferes with other DNS architectures (like domain-joined scenarios). 相反,Azure 会提供没有实际功能的占位符 (reddog.microsoft.com) 。Instead, Azure provides a non-functioning placeholder (reddog.microsoft.com).

如果需要,可以使用 PowerShell 或 API 确定内部 DNS 后缀:If necessary, you can determine the internal DNS suffix by using PowerShell or the API:

如果不想将查询转发到 Azure,应提供自己的 DNS 解析。If forwarding queries to Azure doesn't suit your needs, you should provide your own DNS solution. DNS 解决方案需要:Your DNS solution needs to:

  • 提供合适的主机名解析(例如,通过 DDNS)。Provide appropriate host name resolution, via DDNS, for example. 如果使用 DDNS,则可能需要禁用 DNS 记录清理。If you are using DDNS, you might need to disable DNS record scavenging. Azure DHCP 租约时间很长,进行清理可能会导致 DNS 记录过早删除。Azure DHCP leases are long, and scavenging might remove DNS records prematurely.
  • 提供适当的递归式解析来解析外部域名。Provide appropriate recursive resolution to allow resolution of external domain names.
  • 可以从其所服务的客户端进行访问(端口 53 上的 TCP 和 UDP),并可访问 Internet。Be accessible (TCP and UDP on port 53) from the clients it serves, and be able to access the internet.
  • 禁止从 Internet 进行访问,减少外部代理带来的威胁。Be secured against access from the internet, to mitigate threats posed by external agents.

Note

为获得最佳性能,在将 Azure VM 用作 DNS 服务器时,应禁用 IPv6。For best performance, when you are using Azure VMs as DNS servers, IPv6 should be disabled. 公共 IP 地址 应分配给每个 DNS 服务器 VM。A public IP address should be assigned to each DNS server VM. 如需获取更多性能分析和优化(使用 Windows Server 作为 DNS 服务器时),请参阅递归 Windows DNS Server 2012 R2 的名称解析性能For additional performance analysis and optimizations when you are using Windows Server as your DNS server, see Name resolution performance of a recursive Windows DNS Server 2012 R2.

Web 应用Web apps

假设你需要执行从使用应用服务生成的、已链接到某个虚拟网络的 Web 应用到同一虚拟网络中的 VM 的名称解析。Suppose you need to perform name resolution from your web app built by using App Service, linked to a virtual network, to VMs in the same virtual network. 除了设置具有 DNS 转发程序(可向 Azure 转发查询)的自定义 DNS 服务器(虚拟 IP 为 168.63.129.16)以外,还需要执行以下步骤:In addition to setting up a custom DNS server that has a DNS forwarder that forwards queries to Azure (virtual IP 168.63.129.16), perform the following steps:

  1. 根据将应用与虚拟网络集成中所述,为 Web 应用启用虚拟网络集成(如果尚未启用)。Enable virtual network integration for your web app, if not done already, as described in Integrate your app with a virtual network.

  2. 在 Azure 门户中,对于托管 Web 应用的应用服务计划,选择“网络”>“虚拟网络集成”下的“同步网络” 。In the Azure portal, for the App Service plan hosting the web app, select Sync Network under Networking, Virtual Network Integration.

    虚拟网络名称解析的屏幕截图

如需从使用应用服务构建的链接到虚拟网络的 Web 应用对不同虚拟网络中的 VM 执行名称解析,需要同时在两个虚拟网络中使用自定义 DNS 服务器,如下所示:If you need to perform name resolution from your web app built by using App Service, linked to a virtual network, to VMs in a different virtual network, you have to use custom DNS servers on both virtual networks, as follows:

  • 在某个也可向 Azure 中的递归解析程序(虚拟 IP 为 168.63.129.16)转发查询的 VM 上的目标虚拟网络中设置 DNS 服务器。Set up a DNS server in your target virtual network, on a VM that can also forward queries to the recursive resolver in Azure (virtual IP 168.63.129.16). DNS 转发器示例可在 Azure 快速入门模板库GitHub 中获取。An example DNS forwarder is available in the Azure Quickstart Templates gallery and GitHub.
  • 在某个 VM 上的源虚拟网络中设置 DNS 转发程序。Set up a DNS forwarder in the source virtual network on a VM. 将此 DNS 转发器配置为向目标虚拟网络中的 DNS 服务器转发查询。Configure this DNS forwarder to forward queries to the DNS server in your target virtual network.
  • 在源虚拟网络的设置中配置源 DNS 服务器。Configure your source DNS server in your source virtual network's settings.
  • 遵照将应用与虚拟网络集成中的说明,为 Web 应用启用虚拟网络集成以链接到源虚拟网络。Enable virtual network integration for your web app to link to the source virtual network, following the instructions in Integrate your app with a virtual network.
  • 在 Azure 门户中,对于托管 Web 应用的应用服务计划,选择“网络”>“虚拟网络集成”下的“同步网络” 。In the Azure portal, for the App Service plan hosting the web app, select Sync Network under Networking, Virtual Network Integration.

指定 DNS 服务器Specify DNS servers

使用自己的 DNS 服务器时,Azure 允许为每个虚拟网络指定多个 DNS 服务器。When you are using your own DNS servers, Azure provides the ability to specify multiple DNS servers per virtual network. 也可以针对每个网络接口(适用于 Azure 资源管理器)或云服务(适用于经典部署模型)指定多个 DNS 服务器。You can also specify multiple DNS servers per network interface (for Azure Resource Manager), or per cloud service (for the classic deployment model). 为网络接口或云服务指定 DNS 服务器时,其优先级高于为虚拟网络指定的 DNS 服务器。DNS servers specified for a network interface or cloud service get precedence over DNS servers specified for the virtual network.

Note

不应直接在 VM 中编辑网络连接属性,例如 DNS 服务器 IP。Network connection properties, such as DNS server IPs, should not be edited directly within VMs. 这是因为,在更换虚拟网络适配器后,可能会在服务修复过程中擦除这些属性。This is because they might get erased during service heal when the virtual network adaptor gets replaced. 这同时适用于 Windows VM 和 Linux VM。This applies to both Windows and Linux VMs.

使用 Azure 资源管理器部署模型时,可为虚拟网络和网络接口指定 DNS 服务器。When you are using the Azure Resource Manager deployment model, you can specify DNS servers for a virtual network and a network interface. 有关详细信息,请参阅管理虚拟网络管理网络接口For details, see Manage a virtual network and Manage a network interface.

Note

如果为虚拟网络选择自定义 DNS 服务器,则必须至少指定一个 DNS 服务器 IP 地址;否则,虚拟网络将忽略配置,而改用由 Azure 提供的 DNS。If you opt for custom DNS server for your virtual network, you must specify at least one DNS server IP address; otherwise, virtual network will ignore the configuration and use Azure-provided DNS instead.

使用经典部署模型时,可以在 Azure 门户或网络配置文件中指定虚拟网络的 DNS 服务器。When you are using the classic deployment model, you can specify DNS servers for the virtual network in the Azure portal or the Network Configuration file. 对于云服务器,可以通过服务配置文件或者在 PowerShell 中使用 New-AzureVM 指定 DNS 服务器。For cloud services, you can specify DNS servers via the Service Configuration file or by using PowerShell, with New-AzureVM.

Note

如果更改已部署的虚拟网络或虚拟机的 DNS 设置,则需重启每个受影响的 VM,所做的更改才会生效。If you change the DNS settings for a virtual network or virtual machine that is already deployed, you need to restart each affected VM for the changes to take effect.

后续步骤Next steps

Azure 资源管理器部署模型Azure Resource Manager deployment model:

经典部署模型:Classic deployment model: