Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 786539
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T21:03:30+00:00 2026-05-14T21:03:30+00:00

Is it possible to add a record to the dns cache from java? Or

  • 0

Is it possible to add a record to the dns cache from java? Or will I have to use the JNI?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T21:03:30+00:00Added an answer on May 14, 2026 at 9:03 pm

    Is it possible to add a record to the dns cache from java? Or will I have to use the JNI?

    Assuming that you are talking about the DNS cache that Java applications use, the answer is No in both cases.

    The cache is implemented in the java.net.InetAddress class; refer here for the source code. As you can see, the cache is implemented using private static attributes and all of the classes and methods involved are private or package private. In short, the only way you could get at the cache would be by using nasty reflection tricks to subvert the Java access rules.

    Since this is implemented in pure Java, JNI won’t help.

    EDIT

    Unfortunately, the link above no longer points to the OpenJDK code :-(.

    FOLLOWUP

    Re: these comments.


    The Java DNS cache? – WineSoaked May 9 ’10 at 3:25


    Sorry no, the system one. I’m trying to proxy the default browser for certain sites and i figured adding a dns record for those sites pointing to my local proxy would be easiest way. – silverbandit91 May 9 ’10 at 5:32

    There is no way to directly plant things in the system DNS cache from Java. Indeed, I don’t even think that Java uses the system DNS cache.

    But there are better alternatives to what you are trying to do:

    • Get your users to configure their browsers to use an ‘autoproxy.pac’ file to determine which proxies to use. IMO, this is the best option.

    • Put entries for the hosts that you want to selectively proxy into “/etc/hosts” and configure (using “/etc/host.conf”) your local resolver to look in “/etc/hosts” before talking to the DNS server. Unfortunately (like cache poisoning) this “pollutes” your DNS with bogus entries, can cause problems when using services other than HTTP / HTTPS.

    Finally, you probably should rethink your goal of doing this totally transparently to your users:

    • If you are doing this to implement some company security or internet access rules, people can “route around” any measures you implement at this level. (You’d be better off firewalling your network and forcing to use a proxy for external access … or something like that.)

    • If you are just trying to implement a useful service, you should use the autoproxy.pac approach which gives the users 1) visibility of what is going on (if they care to look), and 2) the option of opting in or out.

    • If you are trying to do something else …

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 381k
  • Answers 381k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I would use code from http://www.mredkj.com/javascript/numberFormat.html to add commas: function… May 14, 2026 at 10:12 pm
  • Editorial Team
    Editorial Team added an answer Use a union and get rid of the bit-operations: <stdint.h>… May 14, 2026 at 10:12 pm
  • Editorial Team
    Editorial Team added an answer Stream implements the IDisposable interface, but hides the 'official' name… May 14, 2026 at 10:12 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.