LoginSignup
0
1

PowerDNS の API 操作メモ

Last updated at Posted at 2023-07-28

PowerDNS では API 経由でレコードの確認や追加が可能であるが、いつもやり方を忘れるので各種操作のメモ。

ZONE の一覧を取得する

# curl -sk -H 'X-API-Key: <パスワード>' -X GET http://<PowerDNS の IP or FQDN>:8081/api/v1/servers/localhost/zones | jq .
[
  {
    "account": "",
    "catalog": "",
    "dnssec": false,
    "edited_serial": 2023063001,
    "id": "example.hoge.com.",
    "kind": "Native",
    "last_check": 0,
    "masters": [],
    "name": "example.hoge.com.",
    "notified_serial": 0,
    "serial": 2023063001,
    "url": "/api/v1/servers/localhost/zones/example.hoge.com."
  },
  {
    "account": "",
    "catalog": "",
    "dnssec": false,
    "edited_serial": 2023063005,
    "id": "0.168.192.in-addr.arpa.",
    "kind": "Native",
    "last_check": 0,
    "masters": [],
    "name": "0.168.192.in-addr.arpa.",
    "notified_serial": 0,
    "serial": 2023063005,
    "url": "/api/v1/servers/localhost/zones/0.168.192.in-addr.arpa." <------★
  },

   :

ZONE に含まれる各レコードの参照

👆 の API 応答で得られた Zone の名前=url を指定して GET する。

# curl -sk -H 'X-API-Key: <パスワード>' -X GET http://<PowerDNS の IP or FQDN>:8081/api/v1/servers/localhost/zones/0.168.192.in-addr.arpa. | jq .
 :

    {
      "comments": [],
      "name": "100.0.168.192.in-addr.arpa.",
      "records": [
        {
          "content": "hogehoge.example.hoge.com.",
          "disabled": false
        }
      ],
      "ttl": 3600,
      "type": "PTR"
    },

ZONE へのレコード操作

正引きレコードを追加する場合

以下のような A レコードの json ファイルを作成する。

{
  "rrsets": [
      {
        "comments": [],
        "name": "fugafuga.example.hoge.com.",
        "changetype": "REPLACE",
        "records": [
          {
            "content": "192.168.0.101",
            "disabled": false
          }
        ],
        "ttl": 3600,
        "type": "A"
    }
  ]
}

逆引きレコードを追加する場合

以下のような PTR レコードの json ファイルを作成する。

{
  "rrsets": [
      {
        "comments": [],
        "name": "101.0.168.192.in-addr.arpa.",
        "changetype": "REPLACE",
        "records": [
          {
            "content": "fugafuga.example.hoge.com.",
            "disabled": false
          }
        ],
        "ttl": 3600,
        "type": "PTR"
      }
  ]
}

レコードの削除を行う場合

上記 json ファイルの rrsets.changetypeDELETE に変更する。

{
  "rrsets": [
      {
        "comments": [],
        "name": "101.0.168.192.in-addr.arpa.",
        "changetype": "DELETE",
 :

Zone の作成

新しい zone 用の json ファイルを作成する。

{
    "kind": "Native",
    "masters": [],
    "name": "1.168.192.in-addr.arpa.",
    "nameservers": [
    ]
}

クエリ実行

作成した json ファイルを指定し、各 ZONE に対して PATCH リクエストを発行する。

レコードの場合

# curl -sk -H 'X-API-Key: <パスワード>' -X PATCH -d @xxxxxx.json http://<PowerDNS の IP or FQDN>:8081/api/v1/servers/localhost/zones/<対象 ZONE 名> 

zone の場合

# curl -sk -H 'X-API-Key: <パスワード>' -X POST -d @xxxxxx.json http://<PowerDNS の IP or FQDN>:8081/api/v1/servers/localhost/zones
0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1