java - openjdk中的networkaddress.cache.ttl null
问题描述
当我执行:
System.getProperty("networkaddress.cache.ttl");
Security.getProperty("networkaddress.cache.ttl");
结果为空。
我正在使用高山,openJdk8。我做了一些测试,发现我的资源 dns 正在发生变化,这是我想要的行为,解析 dns,而不是永远缓存。
我读到如果安装了 SecurityManager,默认值为:-1,这意味着“永远缓存 dns”
我没有安装 SecurityManager。
这种情况下的正确行为是什么?未安装 SecurityManager 且 networkaddress.cache.ttl 为空时?dns缓存是否会刷新?
解决方案
这些设置实际上在配置文件中。
开放JDK 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
开放JDK 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
在其他一些版本中,它可以在 /etc 下,例如/etc/java-11-openjdk/security/java.security
使用 AdoptOpenJDK 11,您可以看到TTL 在没有找到安全管理器时设置为 30 秒。
推荐阅读
- javascript - 无法发送“POST”表单,jQuery 不会检测到提交动作
- networking - OSI 层上的以太坊表示
- powershell - 将 PowerShell 脚本作为计划任务运行时出错
- typescript - 将 Typescript 类型固定为 Union 类型
- python - urllib.request.retrieve 以变量为参数到用户指定的文件
- pdf - 如何从内容流中解码数据
- php - 编辑特定产品
- angular - 如何在ionic 3中选择多个图像和视频
- php - php htaccess 重写失败
- vba - 在 Powerpoint 上的固定位置之间同时进行多形状旋转