Skill/spring

JVM DNS TTL 설정

진열사랑 2023. 10. 10. 17:52

출처  :https://m.blog.naver.com/adamdoha/222477256466

Specified in java.security to indicate the caching policy for un-successful name lookups from the name service.. The value is specified as integer to indicate the number of seconds to cache the failure for un-successful lookups.

A value of 0 indicates "never cache". A value of -1 indicates "cache forever".



해석: 기본값은 10이며, DNS 주소를 받아오지 못했을 때의 캐시 정책이다. 조회를 제대로 하지 못하여 캐시 실패에 대한 (초) 값을 나타낸다. 값이 0이면 "캐시 안함", 값이 -1이면 "영구 캐시"를 의미한다.



적용

1. JVM을 사용하는 모든 애플리케이션에 전체적으로 적용하고 싶은 경우



$JAVA_HOME/jre/lib/security/java.security 파일에서 예를 들어서 캐시 정책을 60초로 하고 싶으면 다음과 같이 설정하면 됩니다.

networkaddress.cache.ttl=60


2. 특정 애플리케이션에만 적용하려는 경우

이 때는 애플리케이션 초기화 코드에, networkaddress.cache.ttl을 설정하면 됩니다.

SpringBoot를 예로 들면 다음과 같습니다. 방금 1번과,  눈치채셨겠지만, java의 Security 속성에 설정해주면 됩니다.

...
import java.security.Security;
...
@SpringBootApplication
public class ExampleApplication {
    public static void main(String[] args) {
        disableAddressCache();
        SpringApplication.run(ExampleApplication.class, args);
    }

    private static void disableAddressCache() {
        Security.setProperty("networkaddress.cache.ttl", "0");
        Security.setProperty("networkaddress.cache.negative.ttl", "0");
    }
}




Reference)

https://docs.aws.amazon.com/sdk-for-java/v1/developer-guide/java-dg-jvm-ttl.html


Setting the JVM TTL for DNS Name Lookups - AWS SDK for Java
Setting the JVM TTL for DNS Name Lookups PDF Kindle RSS The Java virtual machine (JVM) caches DNS name lookups. When the JVM resolves a hostname to an IP address, it caches the IP address for a specified period of time, known as ...

docs.aws.amazon.com

https://docs.oracle.com/javase/8/docs/technotes/guides/net/properties.html


Networking Properties
Skip to Content Java Software Java SE Downloads Java SE 8 Documentation Search Networking Properties Java Properties java.net.preferIPv4Stack (default: false) If IPv6 is available on the operating system the underlying native socket will be an IPv6 socket. This allows Java(tm) applications to connec...

docs.oracle.com

https://docs.oracle.com/javase/7/docs/technotes/guides/security/smPortGuide.html#SecurityManagerMethods


Security Managers and the Java SE JDK
Skip to Content Oracle Technology Network Software Downloads Documentation Search Security Managers and the Java SE JDK Introduction Security Model Evolution Security Manager Evolution Security Manager Methods Security Managers in JDK 1.1 Security Managers in the Java SE JDK Installing java.lang.Sec...

docs.oracle.com