openjdk 中的 networkaddress.cache.ttl null

jav*_*Try 4 java java-8

当我执行:

System.getProperty("networkaddress.cache.ttl");
Security.getProperty("networkaddress.cache.ttl");
Run Code Online (Sandbox Code Playgroud)

结果为空。

我正在使用高山,openJdk8。我做了一些测试,发现我的资源 dns 正在发生变化,这是我想要的行为,解析 dns,而不是永远缓存。

我读到如果安装了 SecurityManager,默认值为:-1,这意味着“永远缓存 dns”

我没有安装 SecurityManager。

这种情况下的正确行为是什么?未安装 SecurityManager 且 networkaddress.cache.ttl 为空时?Dns 缓存是否会刷新?

pyb*_*pyb 8

这些设置实际上在配置文件中。

OpenJDK 8

使用 Docker 镜像openjdk:8,当没有安全管理器时,实现使用 30 秒。

/usr/local/openjdk-8/jre/lib/security/java.security

#
# The Java-level namelookup cache policy for successful lookups:
#
# any negative value: caching forever
# any positive value: the number of seconds to cache an address for
# zero: do not cache
#
# default value is forever (FOREVER). For security reasons, this
# caching is made forever when a security manager is set. When a security
# manager is not set, the default behavior in this implementation
# is to cache for 30 seconds.
#
# NOTE: setting this to anything other than the default value can have
#       serious security implications. Do not set it unless
#       you are sure you are not exposed to DNS spoofing attack.
#
#networkaddress.cache.ttl=-1
Run Code Online (Sandbox Code Playgroud)

OpenJDK 11

使用Docker镜像openjdk:11,实现同上。

/usr/local/openjdk-11/conf/security/java.security

#
# The Java-level namelookup cache policy for successful lookups:
#
# any negative value: caching forever
# any positive value: the number of seconds to cache an address for
# zero: do not cache
#
# default value is forever (FOREVER). For security reasons, this
# caching is made forever when a security manager is set. When a security
# manager is not set, the default behavior in this implementation
# is to cache for 30 seconds.
#
# NOTE: setting this to anything other than the default value can have
#       serious security implications. Do not set it unless
#       you are sure you are not exposed to DNS spoofing attack.
#
#networkaddress.cache.ttl=-1
Run Code Online (Sandbox Code Playgroud)

在其他一些版本中,它可以在 /etc 下,例如 /etc/java-11-openjdk/security/java.security

使用 AdoptOpenJDK 11,您可以看到当没有找到安全管理器时TTL 设置为 30 秒

  • 如何知道是否设置了“安全管理器”?有没有办法在运行的jvm上检查这个属性的值? (2认同)
  • @xref `System.getSecurityManager()` 如果没有则返回 `null`:https://docs.oracle.com/javase/tutorial/essential/environment/security.html 我尝试在运行时读取该属性,它是未设置(如问题中所示)。这就是我如何阅读更多相关内容并找到这个:) (2认同)