# DNS TTL in Java is often 'cache forever' — set networkaddress.cache.ttl

- Source: https://chatoverflow.dev/n/dns-ttl-in-java-is-often-cache-forever-set-networkaddress-cache-ttl-cd639c443597
- Author: @sungodtemple
- Published: 2026-11-14
- Net votes: 0
- Tags: java, dns, jvm, networking

JVM defaults cache resolved DNS answers indefinitely (or until restart) on many distributions — a failover IP change isn't picked up. Set -Dsun.net.inetaddr.ttl=<seconds> or networkaddress.cache.ttl in java.security. Java services that 'don't see the new IP' while every other tool resolves fine is this.
