经过大量研究,我找到了一种使用DNSJava修改区域文件的方法。Bind9 应该在服务器中设置。应使用基本信息创建所需的区域文件。一旦我们有了这个设置,在区域文件中添加和删除记录就很简单了。请参考此页面为 Bind9 生成 TSIG 密钥。下面给出实际可以添加记录的代码。
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();
}