JVM和操作系统DNS缓存 [英] JVM and OS DNS Caching

查看:146
本文介绍了JVM和操作系统DNS缓存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在面对JVM和DNS的问题。



我正在阅读的所有内容(包括文档这个)说,我可以使用 networkaddress.cache.ttl 禁用JVM DNS缓存,可以使用 java.security.Security.setProperties ,但是通过使用系统属性的标准方法。我已经成功地将其更改为0,所以在我的JVM中不再有缓存。



但现在,每次调用 InetAddress.getByName(mytest .com),似乎我的JVM正在使用系统 DNS缓存(在我的情况下为Windows 8)。实际上,在方法的两个调用之间,我已经改变了mytest.com的BIND9属性,但IP返回值仍然是一样的。以下是我的Java代码中的工作流程:


  1. setCachePolicyInJVM(0)在BIND9中重新启动

  2. mytest.com 设置为192.168.1。 188 。 b $ b
  3. InetAddress.getByName(mytest.com)。getHostAddress(); - > 192.168.1。 188 在BIND9中重新启动

  4. 设置 mytest.com - > 192.168.1。 160
  5. $ ($)$ {code} InetAddress.getByName(mytest.com)。getHostAddress(); - > 192.168.1。
  6. 刷新Windows DNS

  7. InetAddress。 getByName(mytest.com)。getHostAddress(); - > 192.168.1。

我已经阅读了几次JVM不使用系统缓存,但这是错误的:它显然是。



我们如何强制绕过操作系统 DNS缓存,每个呼叫都有一个新的DNS解析。

解决方案

我跑了对这个问题,或者是非常相似的。那么我所做的就是实现我自己的JVM的DNS提供者,参见如何更改java dns服务提供者的详细信息。你可以使用那里提到的dnsjava或者自己滚动。


I am facing a problem with JVM and DNS.

Everything I'm reading (including the docs and this) says that I can disable JVM DNS caching using networkaddress.cache.ttl, which can be set using java.security.Security.setProperties, but through the standard approach of using system properties. I have successfully changed this to 0, so no more caching in my JVM.

But now, on each call of InetAddress.getByName("mytest.com"), it seems that my JVM is using the system DNS cache (in my case Windows 8). Indeed, between 2 calls of the method, I have changed the BIND9 properties for "mytest.com", but the IP return is still the same. Here is the workflow:

  1. setCachePolicyInJVM(0) in my Java code.
  2. set mytest.com to 192.168.1.188 in BIND9, restart.
  3. InetAddress.getByName("mytest.com").getHostAddress(); -> 192.168.1.188
  4. set mytest.com -> 192.168.1.160 in BIND9, restart.
  5. InetAddress.getByName("mytest.com").getHostAddress(); -> 192.168.1.188 (should be 160 if there was no caching).
  6. Flush the Windows DNS
  7. InetAddress.getByName("mytest.com").getHostAddress(); -> 192.168.1.160

I have read several times that the JVM does not use the system cache, but that is wrong: it clearly does.

How do we force a new DNS resolution on each call, bypassing the OS DNS cache?

解决方案

I think I've run into this problem, or a very similar one. What I did then was to implement my own DNS provider for the JVM, see how to change the java dns service provider for details. You can use the dnsjava mentioned there or roll your own.

这篇关于JVM和操作系统DNS缓存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆