resolving a hostname to an IP address is rather easy in Java by using the InetAddress class like this:
InetAddress address = InetAddress.getByName("www.example.com");
But this method uses the DNS server which is used by the running system.
Is there any way to specify the DNS server that should be used for resolving?
It doesn't decide randomly. You're connected to a router which gets it IP from a company which has DNS servers. They get your request unless you alter the IP manually to another DNS, for instance: OpenDns. Or perhaps you decide on having your own DNS servers.
Type nslookup and hit Enter. The displayed information will be your local DNS server and its IP address. You can specify the DNS server (IP address), type of record, and domain name. Type nslookup and domain name and the command will return the A record for the domain you run a query for.
DNS (Domain Name Server) resolution is the process of translating IP addresses to domain names. When a profile is configured to look up all numeric IP addresses, Webtrends makes a call to the network's DNS server to resolve DNS entries.
If you use Sun Java, you can use this code:
//Override system DNS setting with Google free DNS server
System.setProperty("sun.net.spi.nameservice.nameservers", "8.8.8.8");
System.setProperty("sun.net.spi.nameservice.provider.1", "dns,sun");
See this blog post: How to set a custom DNS server with Java System properties for more details.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With