Java - use system DNS server settings

911 Views Asked by At

I'm running dnsmasq on OSX for local offline development, and I've added 127.0.0.1 as the top DNS server in my network settings. Everything works as expected in the terminal.

My Java tests don't seem to be using the local DNS server, which is a pain as that's the main reason I needed it!

What configuration is needed for Java to pick up system DNS settings? Do I need to pass JVM system properties telling it to ise localhost?

1

There are 1 best solutions below

0
ezsi On

Yes, you need to update system settings to use local dns.

System.setProperty("sun.net.spi.nameservice.nameservers", "127.0.0.1");
System.setProperty("sun.net.spi.nameservice.provider.1", "dns,sun");