1

According to this post there are several ways to configure a custom host resolver in Java, but each of these ways differs from the other and does not work for all java versions between 8 and the most recent.

The post indicated above is 10 years old: does anyone know if in this period a solution has been found that works for all the java versions mentioned above? If so, does anyone have an example code?

5
  • Java invokes the host operating system to resolve dns; why would there be a specific Java DNS resolver by default? The only option I know of would be running your own Java DNS. Which is probably not what you want. Why do you want to do this? Commented Oct 29, 2022 at 8:16
  • I was interested in it for educational purposes. How can I run my Java DNS which works for java version 8 and later? Could you provide a sample code? Commented Oct 29, 2022 at 8:22
  • No one is going to provide "sample code", because no one is doing this. dnsjava is a dns server written in Java. You can run any dns server you like, Unbound for example, then you must configure your operating system to use it. Note: This is still not something Java (as a platform) is designed for. Why would there be a "resolve dns names" in an atypical manner? Commented Oct 29, 2022 at 8:31
  • Rather than starting a server I was wondering if there was a solution similar to this but also working for Java 8. If we could do the same programmatically it would be even better instead of passing a parameter to the JDK. Commented Oct 29, 2022 at 8:42
  • Not that I'm aware of. Good luck! Commented Oct 29, 2022 at 9:02

1 Answer 1

3

After a deep search I found this example that uses the burningwave tools library:

Map<String, String> hostAliases = new LinkedHashMap<>();
hostAliases.put("my.hostname.one", "123.123.123.123");

HostResolutionRequestInterceptor.INSTANCE.install(
    new MappedHostResolver(hostAliases),
    DefaultHostResolver.INSTANCE
);

InetAddress inetAddress = InetAddress.getByName("my.hostname.one");

And here the code to add a DNS server connection based host resolver

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.