Reputation: 414
I am trying to create a DNS service (automation of various DNS operations) to serve our existing private cloud. I am looking for options and ideas to do this. Is there any existing Java API to do this? Please suggest.
I made a research on the possible solutions. I found DNSJava to be a good solution. But I did not find much documentation/examples. The following are some questions which, when answered, can solve my current problems:
I have created a local DNS server for test purpose. It will be really helpful if the examples are given with respect to localhost.
Thank you!
Upvotes: 2
Views: 2408
Reputation: 414
After a lot of research, I found a way to modify the zone files with DNSJava. Bind9 should be setup in the server. Required zone files should be created with basic information. Adding and deleting a record in the zone file is straight forward once we have this setup. Please refer to this page to generate TSIG key for Bind9. The code that can actually add a record is given below.
Name zoneName = null;
String domain = "your.domain";
String host = "hostname";
DNSRecordType type = DNSRecordType.A;
int ttl = 600;
Lookup lookup = new Lookup(Name.fromString("your.domain"));
Record [] records = lookup.run();
if(records != null) {
zoneName = records[0].getName();
}
if(zoneName != null) {
Name hostName = Name.fromString("hostname", zoneName);
Update update = new Update(zoneName);
update.add(hostName, Type.value(type.toString()), 600,
"192.168.2.50");
Resolver resolver = new SimpleResolver();
resolver.setTCP(true);
resolver.setTSIGKey(new TSIG("your.domain.",
"z0pll56C4cwLXYd2HG6WsQ=="));
Message response1 = resolver.send(update);
response = response1.getHeader().toString();
}
Upvotes: 3