How to set up a custom DNS server using java 8 and open JDK?
•
Java
How to use Java 8 and open JDK to set up a custom DNS server to resolve host names? I tried the following from other stack overflow posts, but it doesn't seem to apply to open-jdk-8 Any ideas?
System.setProperty("sun.net.spi.nameservice.nameservers","100.68.0.50"); System.setProperty("sun.net.spi.nameservice.provider.1","dns,sun");
100.68. 0.50 is my DNS server
Solution
The property should be set before any instantiation of InetAddress, because the name service is created statically
Note that many seemingly harmless statements (such as using a static logger in the main class) may cause the InetAddress object to be created under the hood to initialize the name service
Is it valid when you use Java - D... =?
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码