Search code examples
javasecurityparametersdns

How to get and set the value of networkaddress.cache.ttl


I have a java application running in an alpine container. I would like to find a reliable way to determine what is the value of networkaddress.cache.ttl. I tried to use this in the code of the application: java.security.Security.getProperty("networkaddress.cache.ttl"); but it always returns null, even when I use -Dnetworkaddress.cache.ttl=30 in the JAVA_OPTS arguments. So I am doing something wrong obviously but I don't know what. According to this networkaddress.cache.ttl null in openjdk I don't even need to add the argument in JAVA_OPTS because the default value is 30 anyway. Looking at /usr/local/openjdk-8/jre/lib/security/java.security inside the container I can see #networkaddress.cache.ttl=-1 but it is commented out, so I have no idea what the default value is. So how can i reliably check what is the value of networkaddress.cache.ttl?


Solution

  • For reasons unknown to me -Dnetworkaddress.cache.ttl=30 fails to set anything. I managed to set it by adding this to my Dockerfile

    sed -i '313,313 s/^#//' /usr/lib/jvm/zulu8-ca/jre/lib/security/java.security
    sed -i '313,313 s/-1/30/' /usr/lib/jvm/zulu8-ca/jre/lib/security/java.security
    

    Another way it can be done is described here. The idea is to use another file for overriding the security property. Both approaches worked fine for me.