On Tue, 12 Feb 2008, Saran1 wrote:
> I want to resolve the DNS names for the internal and external IPAddresses
> using Java and DNSJava. Below java code resolve the names from 'hosts' file
> first and then contact the DNS Server for resolution.
>
> System.setProperty("sun.net.spi.nameservice.provider.1","dns,dnsjava");
> InetAddress addr = InetAddress.getByName(ipaddress);
> String dnsname = addr.getCanonicalHostName().trim();
> System.out.println("DNS...........:" + dnsname);
>
> But after setting the "dnsjava-2.0.3.jar" in classpath, the above code
> doesn't look my 'hosts' file. Please let me know for any reason behind the
> same.
Because dnsjava is a library implementing the DNS protocol, and /etc/hosts
is not part of the DNS protocol.
> My Requirement:
> 1. Faster the DNS Resolve [using dnsjava.jar]
> 2. First look for 'hosts' file, then contact DNS Server.
>
> Please help me to solve the problem. Any help will be highly appreciated.
You have several options:
1) Do the /etc/hosts lookup yourself.
2) Find or create a patch to dnsjava which implements /etc/hosts file
lookups, and submit it.
Brian
|