Java DNS cache 时效设置备忘
来源:互联网 发布:数据库课程设计选题 编辑:程序博客网 时间:2024/04/29 00:18
Java DNS cache 时效设置备忘
我们知道java的InetAddress会通过自身的cache缓存dns解析结果。
缓存的策略主要有两种,一种是缓存正确解析后的IP地址,还有一种是缓存解析失败后的状态。
这两种策略的时效配置都在 %JRE%\lib\security\java.security 这个文件里。
TTL=Time to Live
networkaddress.cache.ttl
缓存正常解析后的ip,如果在缓存时效内再次lookup时直接返回缓存结果。
缓存时间:
1,在启用 java security manager时,是永久缓存。(PS: jboss, tomcat等app server默认不启用 java security manager,资料见这里)
2,不启用的话,默认是缓存30秒。
3,缓存时间 设为0的话,表示不缓存,设置-1表示永久缓存,正数表示缓存时间(秒)。
缓存时间的描述可以在 %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 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
networkaddress.cache.negative.ttl (default: 10)
缓存失败结果,如果在缓存时效内再次lookup时直接返回错误(减轻DNS服务压力)。默认10秒。
缓存时间 设为0的话,表示不缓存,设置-1表示永久缓存,正数表示缓存时间(秒)。
该配置也能在 %JRE%\lib\security\java.security 这个文件中找到:
# The Java-level namelookup cache policy for failed lookups:
#
# any negative value: cache forever
# any positive value: the number of seconds to cache negative lookup results
# zero: do not cache
#
# In some Microsoft Windows networking environments that employ
# the WINS name service in addition to DNS, name service lookups
# that fail may take a noticeably long time to return (approx. 5 seconds).
# For this reason the default caching policy is to maintain these
# results for 10 seconds.
#
#
networkaddress.cache.negative.ttl=10
除了通过修改 java.security 配置。我们也可以通过在启动jvm时添加一行 -Dsun.net.inetaddr.ttl=value 参数来设置ttl。
另外除了这些官方提供的扩展手段,你甚至可以hack掉InetAddress的cache机制,随心所欲的调整cache策略。
转载请注明原文链接:http://kenwublog.com/java-dns-cache-setting
- Java DNS cache 时效设置备忘
- Java DNS cache 时效
- java如何清理DNS Cache
- [备忘]ubuntu下设置IP和DNS
- 时效!
- 【备忘】JAVA环境变量设置
- java实现清理DNS Cache的方法
- Java中InetAddress 的dns cache应用问题
- DNS污染【备忘】
- DNS的备忘
- 关于DNS cache
- 清除DNS cache
- android DNS cache
- Linux - dnsmasq - dns cache
- android 设置dns ip java码
- 备忘——java如何设置全局变量
- spring-data-redis 自定义注解扩展实现时效设置
- 设置DNS
- android TextView 显示HTML
- 92页E7
- javascript深入了解匿名函数和闭包
- TortoiseSVN使用简介
- django-3
- Java DNS cache 时效设置备忘
- JVM监控工具介绍
- python——urllib模块
- HDU1077-圆覆盖点的个数
- C#中创建、打开、读取、写入、保存Excel的一般性代码
- java Class类
- runtime与include,forward,redirect
- C++指针数组和数组指针--笔试面试系列
- 进程虚拟地址空间与物理内存关系