How to delete A record(s) with specified IP by PowerDNS API?

151 views Asked by At

I wanted to delete record(s) by IP address.

I know how to delete A record by name:

curl -X PATCH --data '{"rrsets": [{"changetype": "DELETE", "type": "A", "name": "test.fqdn."}]}' -H 'X-API-Key: secret' http://127.0.0.1:8081/api/v1/servers/localhost/zones/zonename

Is the way to do this by IP address?

1

There are 1 answers

0
kalu Wang On

Simple answer: not support.

Long answer:

Based on rrset doc, DELETE only supports name.

Must be empty when changetype is set to DELETE.

Here is the script to test

# Add record 192.168.9.9
pdnsutil --config-dir /etc/powerdns add-record  test.com test A 192.168.9.9

# Add record 192.168.9.10 to the same name
pdnsutil --config-dir /etc/powerdns add-record  test.com test A 192.168.9.10

# List the record, and you can see 2 records on the same name
pdnsutil --config-dir /etc/powerdns  list-zone test.com
$ORIGIN .
test.com    60  IN  SOA a.misconfigured.powerdns.server hostmaster.test.com 1 10800 3600 604800 3600
test.test.com   60  IN  A   192.168.9.9
test.test.com   60  IN  A   192.168.9.10

# Try DELETE with IP 
curl -k  -X PATCH --data '{"rrsets": [{"changetype": "DELETE", "type": "A", "name":"test.test.com.",  "records": ["192.168.9.9"]}]}' -H 'X-API-Key: secret'  https://localhost/api/v1/servers/localhost/zones/test.com

# List again, and you can see all test.test.com are removed.
pdnsutil --config-dir /etc/powerdns  list-zone test.com
$ORIGIN .
test.com    60  IN  SOA a.misconfigured.powerdns.server hostmaster.test.com 1 10800 3600 604800 3600