

本文属于机器翻译版本。若本译文内容与英语原文存在差异，则一律以英文原文为准。

# 解析程序委托规则教程
<a name="outbound-delegation-tutorial"></a>

 委托规则允许 VPC 解析器通过指定的出站终端节点访问托管委派区域的域名服务器。虽然转发规则通知 VPC 解析器通过出站终端节点将 DNS 查询转发到与指定域名匹配的域名服务器，但委派规则通知 VPC 解析器通过返回委托的 NS 记录时指定的出站终端节点访问委派域名服务器。当 DNS 响应中的 NS 记录与委派记录中指定的域名匹配时，VPC 解析器会向委派域名服务器发送查询。

## 使用 Resolver 端点出站委托的步骤
<a name="delegation-steps"></a>

1. 在 VPC 中创建一个解析器出站终端节点，您希望通过该终端节点向网络上的解析器发出 DNS 查询。

   您可以使用以下 API 或 CLI 命令：
   + [`CreateResolverEndpoint` API](https://docs.aws.amazon.com/Route53/latest/APIReference/API_route53resolver_CreateResolverEndpoint.html)
   + [`create-resolver-endpoint` CLI](https://docs.aws.amazon.com/cli/latest/reference/route53resolver/create-resolver-endpoint.html)

1. 创建一个或多个委托规则，这些规则指定应通过指定的出站端点将查询委托到您的网络的域名。

   使用 CLI 创建委托规则的示例：

   ```
   aws route53resolver create-resolver-rule \
   --region REGION \
   --creator-request-id delegateruletest \
   --delegation-record example.com \
   --name delegateruletest \
   --rule-type DELEGATE \
   --resolver-endpoint-id outbound endpoint ID
   ```

1. 将委托规则与您想要委托查询的委托规则相关联。 VPCs 

   您可以使用以下 API 或 CLI 命令：
   + [AssociateResolverRule](https://docs.aws.amazon.com/Route53/latest/APIReference/API_route53resolver_AssociateResolverRule.html)API。
   + [associate-resolver-rules](https://docs.aws.amazon.com/cli/latest/reference/route53resolver/associate-resolver-rule.html)CLI 命令。

## Resolver 出站端点支持的委托类型
<a name="delegation-types"></a>

VPC 解析器支持两种类型的出站委派：
+ 路由 53 私有托管区域到 VPC 解析器出站委派：

   使用出站委托，将私有托管区中的子域委托给本地 DNS 服务器或 Internet 上的公有托管区。此出站委托允许您在私有托管区和委托区域之间分配 DNS 记录的管理。根据您的 DNS 设置，可以在私有托管区中使用或不使用粘附记录进行委托。有关更多信息，请参阅 [私有托管区到出站](#phz-to-outbound-delegation)。
+ VPC 解析器出站到出站委托：

   使用出站到出站委托，将子域从您的本地 DNS 服务器委托给位于相同或不同位置的另一个本地服务器。这类似于从私有托管区委托给出站端点，您可以在其中委托给本地名称服务器上托管的区域。有关更多信息，请参阅 [出站到出站](#outbound-to-outbound-delegation)。

### 通往 VPC Resolver 的 Route 53 私有托管区域出站委派示例配置
<a name="phz-to-outbound-delegation"></a>

 假设有一个 DNS 设置，其中父托管区托管在 Amazon VPC 的 Route 53 私有托管区中，子域委托给在欧洲、亚洲和北美洲托管的名称服务器。所有 DNS 查询都通过 VPC 解析器传递。

按照示例步骤配置您的私有托管区域和 VPC 解析器。

**配置出站委托的私有托管区**

1. 对于私有托管区设置：

   父托管区：`hr.example.com`

   ```
   $TTL    86400 ; 24 hours
   $ORIGIN hr.example.com
   @  1D  IN     SOA @    root (20200322001 3H 15 1w 3h)
   @  1D  IN  NS @
   eu.hr.example.com IN NS ns1.eu.hr.example.com.
   apac.hr.example.com IN NS ns2.apac.hr.example.com.
   na.hr.example.com IN NS ns3.na.hr.example.net. # Out of Zone Delegation
   
   ns1.eu.hr.example.com IN A 10.0.0.30 # Glue Record
   ns2.apac.hr.example.com IN A 10.0.0.40 # Glue Record
   ```

1. 对于欧洲本地区域中的本地名称服务器：
   + 托管区：`eu.hr.example.com` NS IP：`10.0.0.30`

   ```
   $TTL    86400 ; 24 hours
   $ORIGIN eu.hr.example.com
   @  1D  IN     SOA @    root (20200322001 3H 15 1w 3h)
   @  1D  IN  NS @
   
   test.eu.hr.example.com IN A 1.2.3.4
   ```

1. 对于亚洲本地区域中的本地名称服务器：

   托管区：`apac.hr.example.com`、`10.0.0.40`

   APAC 名称服务器可以将子域委托给其他名称服务器。

   ```
   $TTL    86400 ; 24 hours
   $ORIGIN apac.hr.example.com
   @  1D  IN     SOA @    root (20200322001 3H 15 1w 3h)
   @  1D  IN  NS @
   
   test.apac.hr.example.com IN A 5.6.7.8
   engineering.apac.hr.example.com IN NS ns1.engineering.apac.hr.example.com
   sales.apac.hr.example.com IN NS ns2.sales.apac.hr.example.com
   ns1.engineering.apac.hr.example.com IN A 10.0.0.80
   ns2.sales.apac.hr.example.com IN A 10.0.0.90
   ```

   托管区：`engineering.apac.hr.example.com`、`10.0.0.80`

   ```
   $TTL 86400 ; 24 hours
   $ORIGIN engineering.apac.hr.example.com
   @ 1D IN SOA @ root (20200322001 3H 15 1w 3h)
   @ 1D IN NS @
   test.engineering.apac.hr.example.com IN A 1.1.1.1
   ```

1. 对于北美洲本地区域中的本地名称服务器：

   托管区：`na.hr.example.net` NS IP：`10.0.0.50`

   ```
   $TTL    86400 ; 24 hours
   $ORIGIN na.hr.example.net
   @  1D  IN     SOA @    root (20200322001 3H 15 1w 3h)
   @  1D  IN  NS @
   ns3.na.hr.example.net. IN A 10.0.0.50
   test.na.hr.example.com  IN A 9.10.11.12
   ```

**VPC 解析器设置**
+ 对于 VPC 解析器，您需要设置一条转发规则和两条委托规则：

  **转发规则**

  1. 用于转发 out-of-zone委派记录，因此 Route 53 VPC 解析器知道委托的 NS 的 IP 以转发初始请求。

     domain-name：`hr.example.net` target-ips：`10.0.0.50`

  **委托规则**

  1. 区域内委托的委托规则：

     委托记录：`hr.example.com`

  1. 区域外委托的委托规则：

     委托记录：`hr.example.net`

### 出站到出站委托示例配置
<a name="outbound-to-outbound-delegation"></a>

 不是将父托管区置于 Amazon VPC 中，而是假设有一个 DNS 设置，其中父托管区位于本地中心位置，而子域被委托给在欧洲、亚洲和北美洲托管的名称服务器。所有 DNS 查询都通过 VPC 解析器传递。

按照示例步骤配置您的本地 DNS 和 VPC 解析器。

**配置本地 DNS**

1. 对于本地中心区域中的本地名称服务器：
   + **父托管区：**`hr.example.com`

     托管区 `hr.example.com`，NS IP：`10.0.0.20`

   ```
   $TTL    86400 ; 24 hours
   $ORIGIN hr.example.com
   @  1D  IN     SOA @    root (20200322001 3H 15 1w 3h)
   @  1D  IN  NS @
   eu.hr.example.com IN NS ns1.eu.hr.example.com.
   apac.hr.example.com IN NS ns2.apac.hr.example.com.
   na.hr.example.com IN NS ns3.na.hr.example.net. # Out of zone delegation
   
   ns1.eu.hr.example.com IN A 10.0.0.30 # Glue record
   ns2.apac.hr.example.com IN A 10.0.0.40 # Glue record
   ```

1.  对于欧洲本地区域中的本地名称服务器（欧洲、亚洲和北美洲名称服务器的配置与私有托管区的出站委托配置相同）：
   + 托管区：`eu.hr.example.com` NS IP：`10.0.0.30`

   ```
   $TTL    86400 ; 24 hours
   $ORIGIN eu.hr.example.com
   @  1D  IN     SOA @    root (20200322001 3H 15 1w 3h)
   @  1D  IN  NS @
   
   test.eu.hr.example.com IN A 1.2.3.4
   ```

1. 对于亚洲本地区域中的本地名称服务器：

   托管区：`apac.hr.example.com`、`10.0.0.40`

   APAC 名称服务器可以将子域委托给其他名称服务器。

   ```
   $TTL    86400 ; 24 hours
   $ORIGIN apac.hr.example.com
   @  1D  IN     SOA @    root (20200322001 3H 15 1w 3h)
   @  1D  IN  NS @
   
   test.apac.hr.example.com IN A 5.6.7.8
   engineering.apac.hr.example.com IN NS ns1.engineering.apac.hr.example.com
   sales.apac.hr.example.com IN NS ns2.sales.apac.hr.example.com
   ns1.engineering.apac.hr.example.com IN A 10.0.0.80
   ns2.sales.apac.hr.example.com IN A 10.0.0.90
   ```

   托管区：`engineering.apac.hr.example.com`、`10.0.0.80`

   ```
   $TTL 86400 ; 24 hours
   $ORIGIN engineering.apac.hr.example.com
   @ 1D IN SOA @ root (20200322001 3H 15 1w 3h)
   @ 1D IN NS @
   test.engineering.apac.hr.example.com IN A 1.1.1.1
   ```

1. 对于北美洲本地区域中的本地名称服务器：

   托管区：`na.hr.example.net` NS IP：`10.0.0.50`

   ```
   $TTL    86400 ; 24 hours
   $ORIGIN na.hr.example.net
   @  1D  IN     SOA @    root (20200322001 3H 15 1w 3h)
   @  1D  IN  NS @
   ns3.na.hr.example.net. IN A 10.0.0.50
   test.na.hr.example.com  IN A 9.10.11.12
   ```

**VPC 解析器设置**
+ 对于 VPC 解析器，您需要设置转发规则和委托规则：

  **转发规则**

  1. 对于转发初始请求，以便将查询转发到位于中心位置的父托管区 `hr.example.com`：

     domain-name：`hr.example.com` target-ips：`10.0.0.20`

  1. 为了转发 out-of-zone委派记录，让 VPC 解析器知道委托域名服务器的 IP 地址来转发初始请求：

     domain-name：`hr.example.net` target-ips：`10.0.0.50`

  **委托规则**

  1. 区域内委托的委托规则：

     委托记录：`hr.example.com`

  1. 区域外委托的委托规则：

     委托记录：`hr.example.net`