文档首页> 云解析服务 DNS> API参考> 应用示例> 示例2:创建内网域名解析
更新时间:2023-12-07 GMT+08:00
分享

示例2:创建内网域名解析

场景描述

如果用户想要使云服务能够不经过公网,直接使用内网域名访问云服务器,可以通过DNS为云服务器创建一个内网域名,并为该域名添加A类型记录集。

下面介绍如何通过调用创建单个内网ZoneAPI和创建单个Record SetAPI创建内网域名和添加记录集。API的调用方法请参见如何调用API

通过IAM服务获取到的Token有效期为24小时,需要使用同一个Token鉴权时,可以先将Token缓存,避免频繁调用。

前提条件

您需要规划内网域名所在的区域信息,并根据区域确定调用API的Endpoint。详细请参见终端节点(Endpoint)

涉及API

当您使用Token认证方式完成认证鉴权时,需要获取用户Token并在调用接口时增加“X-Auth-Token”到业务接口请求消息头中。

  • IAM获取token的API
  • DNS创建内网Zone的API
  • DNS创建Record Set的API

具体步骤

  1. Token认证,具体操作请参考认证鉴权
  2. 在Request Header中增加“Content-Type”和“X-Auth-Token”。
  3. 在Request Body中传入参数如下:
    {
        "name": "example.com.",  //域名(必选String)
        "description": "This is an example zone.", //域名的描述信息(可选String)
        "zone_type": "private", //域名类型(可选String)
        "email": "xx@example.com", //管理该域名的管理员邮箱(可选String)
        "router": {
            "router_id": "19664294-0bf6-4271-ad3a-94b8c79c6558",   //VPC的ID(必选String)
            "router_region": "xx"  //VPC所在Region(可选String)
         }
    }
  4. 发送“POST https://DNS的Endpoint/v2/zones”。
  5. 请求消息发送后,收到响应消息。
    • 响应消息包括成功和失败两类情况,本文以响应成功为例进行介绍。
    • 若请求消息响应失败则会返回错误码及对应的错误信息说明,详细错误码信息请参见错误码
    • 响应消息的要素说明请参见创建单个内网Zone
    • 响应消息的返回值请参见状态码

    请求成功的响应消息举例如下:

    STATUS CODE 200
    {
        "id": "ff8080825b8fc86c015b94bc6f8712c3",
        "name": "example.com.",
        "description": "This is an example zone.",
        "email": "xx@example.com",
        "ttl": 300,
        "serial": 1,
        "masters": [],
        "status": "PENDING_CREATE",
        "links": {
            "self": "https://Endpoint/v2/zones/ff8080825b8fc86c015b94bc6f8712c3"
        },
        "pool_id": "ff8080825ab738f4015ab7513298010e",
        "project_id": "e55c6f3dc4e34c9f86353b664ae0e70c",
        "zone_type": "private",
        "created_at": "2017-04-22T08:17:08.997",
        "updated_at": null,
        "record_num": 0,
        "router": {
            "status": "PENDING_CREATE",
            "router_id": "19664294-0bf6-4271-ad3a-94b8c79c6558",
            "router_region": "xx"
        }
    }
  6. 在Request Header中增加“Content-Type”和“X-Auth-Token”。
  7. 在Request Body中传入参数如下:
    {
        "name": example.com.", //域名(必选String)
        "description": "This is an example record set.", //记录集的描述信息(可选String)
        "type": "A", //记录集类型(必选String)
        "ttl": 3600, //记录集有效缓存时间(可选Integer)
        "records": [ 
            "192.168.10.1", 
            "192.168.10.2"
        ] //记录集的值(必选List<String>)
    }
  8. 发送“POST https://DNS的Endpoint/v2/zones/{zone_id}/recordsets”,其中,zone_id为待添加记录集的域名ID。
  9. 请求消息发送后,收到响应消息。
    STATUS CODE 200
    {
        "id": "2c9eb155587228570158722b6ac30007",
        "name": "example.com.",
        "description": "This is an example record set.",
        "type": "A",
        "ttl": 300,
        "records": [
            "192.168.10.1",
            "192.168.10.2"
        ],
        "status": "PENDING_CREATE",
        "links": {
            "self": "https://Endpoint/v2/zones/2c9eb155587194ec01587224c9f90149/recordsets/2c9eb155587228570158722b6ac30007"
        },
        "zone_id": "ff8080825b8fc86c015b94bc6f8712c3",
        "zone_name": "example.com.",
        "create_at": "2017-04-22T08:17:08.997",
        "update_at": null,
        "default": false,
        "project_id": "e55c6f3dc4e34c9f86353b664ae0e70c"
    }
分享:

    相关文档

    相关产品