Update: This article does a great job of explaining how to set up dns that you can control programmatically: http://rkuzmik.blogspot.com/2006/08/local-managed-dns-java_11.html. I implemented sun.net.spi.nameservice.NameService
, and sun.net.spi.nameservice.NameServiceDescriptor
and was able to specify custom dns entries that way.
One thing to note is that InetAddress
caches domain name/ip addresses aggressively. In other words, for example, once you create a InetAddress
object for my.domain.com
resolving to 127.0.0.1
, it's difficult or impossible to change it while the program is running because of InetAddress
cache.
I think you could also use this (which appears to be a wrapper around the sun stuff I used):
http://www.xbill.org/dnsjava/dnsjava-current/doc/org/xbill/DNS/spi/DNSJavaNameService.html