xuanyuanaosheng / xuanyuanaosheng.github.io

个人网站:灵梦缘
https://xuanyuanaosheng.github.io/
0 stars 0 forks source link

DNS系统-- PowerDNS #26

Open xuanyuanaosheng opened 3 hours ago

xuanyuanaosheng commented 3 hours ago

官方网站

  1. https://www.powerdns.com/
  2. https://github.com/PowerDNS/pdns
  3. 安装文档: https://doc.powerdns.com/authoritative/installation.html#redhat-based-systems
  4. API 使用: https://doc.powerdns.com/authoritative/backends/remote.html#api

组件

  1. PowerDNS Authoritative Nameserver
  2. The PowerDNS Recursor
  3. 需要数据库Mysql 或者PostgreSQL

一个典型的配置

Hostname IP application VIP accountypassword DNS
xxdcdns001.me 10.28.41.1 Pdns 10.28.41.101 powerdns.me
xxdcdns002.me 10.28.41.2 Pdns
xxdcdns003.me 10.28.41.3 pdns-recursor 10.28.41.102
xxdcdns004.me 10.28.41.4 pdns-recursor
xxdcdns005.me 10.28.41.10 mysql master
xxdcdns006.me 10.28.41.11 mysql slave

搭建步骤

API测试

  1. PowerDNS的监控地址:

    curl http://10.28.41.101:8081/metrics
  2. 查询一个zone里面所有的记录

    curl -v -H 'X-API-Key: dzhZdHlKRk5nQlpXdVY1' http://powerdns.me/api/v1/servers/localhost/zones
  3. 创建一个新的Zone

    curl -X POST --data '{"name":"example.org", "kind": "Master","dnssec":false,"soa-edit":"INCEPTION-INCREMENT","masters": [], "nameservers": ["ns1.example.org"]}' -v -H 'X-API-Key: changeme' http://powerdns.me/servers/localhost/zones | jq .
  4. 新建DNS记录

    curl -X PATCH --data '{"rrsets": [ {"name": "test.example.org", "type": "A", "changetype": "REPLACE", "records": [ {"content": "192.168.9.9", "disabled": false, "name": "test.example.org", "ttl": 1800, "type": "A", "priority": 0 } ] } ] }' -H 'X-API-Key: changeme' http://powerdns.me/servers/localhost/zones/example.org | jq .

参考文档

  1. https://stackoverflow.com/questions/65422787/how-change-or-delete-a-record-by-powerdns-api
xuanyuanaosheng commented 2 hours ago

示例

  1. 批量修改DNS的A记录
    
    api_key="cajkbcksjbkcsacslpXAX"
    content_type="application/json"
    list=$(dirname $(readlink -f "$0"))/list/dns.list

while read line;do

存放dns的域名

name=$(echo $line |awk '{print $1}')

存放DNS的IP

content=$(echo $line |awk '{print $2}') zone=$(echo $name |awk -F. 'BEGIN {OFS="."}{$1="";print}' |sed 's/.//') pdns_api_url="http://powerdns.me/api/v1/servers/localhost/zones/$zone"

curl -H "X-API-Key: $api_key" -H "Content-Type: $content_type" -s -X PATCH --data \ '{"rrsets": [{"changetype": "REPLACE", "type": "A", "name": "'"$name."'", "ttl": "1800", "records": [{"content": "'"$content"'", "disabled": false}]}]}' \ $pdns_api_url && echo "Modifying $name to $content Succeeded!" done < $list


2.  批量修改Cname

api_key="cajkbcksjbkcsacslpXAX" content_type="application/json" list=$(dirname $(readlink -f "$0"))/list/dns.list

while read line;do name=$(echo $line |awk '{print $1}') content=$(echo $line |awk '{print $2}') zone=$(echo $name |awk -F. 'BEGIN {OFS="."}{$1="";print}' |sed 's/.//') pdns_api_url="http://powerdns.me/api/v1/servers/localhost/zones/$zone"

curl -H "X-API-Key: $api_key" -H "Content-Type: $content_type" -s -X PATCH --data \ '{"rrsets": [{"changetype": "REPLACE", "type": "CNAME", "name": "'"$name."'", "ttl": "60", "records": [{"content": "'"$content."'", "disabled": false}]}]}' \ $pdns_api_url && echo "Modifying $name to $content Succeeded!" done < $list