mjk mjk - 4 years ago 147
Linux Question

Flushing linux DNS from JAVA

We have a RC module that gets dropped into our cloud servers during hot deployment. To that end, I need a way to flush the DNS programmatically from within JAVA. The best solution that I can think of is to just have java fire an external shell script, however I'm not having any luck. I've tried the "normal" procedures to an avail:

1) restarting nscd service (not installed in these servers)

2) /etc/init.d/networking restart (no effect)

3) /etc/init.d/dns-clean start (no effect)

Anyone have any more suggestions?

(NOTE: this is a re-word of a previous post that must have been determined as being "non-development" related...)


Answer Source

This is JVM implementation dependent. On Oracle JDK, you need to set the networkaddress.cache.ttl and networkaddress.cache.negative.ttl security properties (in $JAVA_HOME/lib/security/java.security). The factory default is to cache positive answers forever.

AFAIK there is no way to flush the cache at runtime.

See http://docs.oracle.com/javase/7/docs/technotes/guides/net/properties.html

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download