I want to choose what DNS server to use. I will make potentially multiple choices in the same JVM. I want to resolve IP addresses from hostnames.
Things I have considered:
Using
System.setProperty
to set DNS settings for Java, but scoping it using classloaders. However, it appears that theSystem
class cannot be loaded differently.Using the dnsjava project. However, I don't see this feature supported. At best, it appears that I would have to handle A record, CNAME records, AAAA records, etc. correctly to get this to work.
What is the easiest way to use a different DNS server in a non-global way?