2

I have a Java desktop application (deployed on Windows) that needs to know about a bunch of different hostnames/IPs. I prefer to use hostnames in the software, as it is more descriptive/less fragile than putting in IP addresses. However, this implies that the Windows machines need knowledge of this mapping.

Both the desktop application and the server software they are talking to are deployed inside a private network. There is no existing DNS service on the network that I am able to take advantage of.

The server software the desktops are talking to already have a hosts file defined with all of this information. In the past, I have included this hosts file with my desktop installer, and basically clobbered the Windows machine's host file. That's pretty ugly and I'd rather not do that again. I was hoping I could basically deploy my hosts file inside my desktop application, and run some kind of name service inside the application that is populated with the hosts file information. That way I don't affect other applications, or mess with the desktop's host file.

I found this article that describes implementing your own NameService class. This is the kind of solution I was looking for, however, it uses internal Sun classes (which I can get away with here, but I'd rather not have to). Also, the article is quite old (2006). In the Java 7 API, the network properties the article mentions are no longer listed. Is there a better/more modern way to do this?

1
  • Sounds like you're doing something pretty kludgy / hacky anyway. If I were you I'd opt for the quickest solution and not worry if its dirty :) Commented Apr 12, 2012 at 17:32

2 Answers 2

1

Try with a project like JDNSS.

However if you search on the web you can find many links about this topic.

Sign up to request clarification or add additional context in comments.

3 Comments

I don't really want a full-blown DNS server, however. I just want my application to be aware of a fixed-set of hostname/ip mappings. I don't want to mess up other applications, or run an extra process.
So, if your needs are so simple, why don't you update your /etc/hosts file?
the problem is on my client computers running Windows. I don't have full control of these machines, so updating their hosts file is not polite behaviour at best, and possibly catastrophic if another application alters the host file and removes my entries.
0

I don't understand the complexity, replacing NameServer classes etc.. If all you need is a couple of hostname-ip mapping, have an array with hostanames and IPs and lookup your names in that array. Or have a file formatted like hosts, put the file in your application folder and populate the aforementioned array from that file.

The good solution would be to have a local DNS server though, like DNSMASQ or BIND.

1 Comment

Yeah, this is basically what I ended up doing.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.