For testing we have a DNS server that will respond with dummy records. Previously we could make java use our DNS server (here it is just using local host) by using:
"-Dsun.net.spi.nameservice.nameservers=127.0.0.1",
"-Dsun.net.spi.nameservice.provider.1=dns,sun",
This no longer works under jdk11. Is it possible to specify the DNS server to use under jdk11? If so how?
Edit: I also attempted:
-Djava.naming.provider.url=dns://127.0.0.1
from https://github.com/AdoptOpenJDK/openjdk-jdk11/blob/master/src/jdk.naming.dns/share/classes/com/sun/jndi/dns/DnsContextFactory.java but that did not work either.
Defining an alternative DNS server is already not supported: https://bugs.java.com/bugdatabase/view_bug.do?bug_id=JDK-8134577
For testing you should use an alternative hosts file that could be defined by the -Djdk.net.hosts.file=path_to_alternative_hosts_file
JVM option.
For example if you have a file with following content at D:\test\hosts
10.20.30.40 google.com www.google.com
Running this code with -Djdk.net.hosts.file=D://test/hosts
public static void main(String[] args) throws UnknownHostException {
InetAddress address = InetAddress.getByName("google.com");
System.out.println(address);
}
will print:
google.com/10.20.30.40
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With