title: How to configure hostname resolution to use a custom DNS server in Java?
body: <p><a href="http://docs.oracle.com/javase/7/docs/api/java/net/InetAddress.html" rel="noreferrer">java.net.InetAddress</a> resolves hostnames using the local machine's default host-name resolver by default:</p>
  
  <blockquote>
    <p>Host name-to-IP address resolution is accomplished through the use of a combination of local machine configuration information and network naming services such as the Domain Name System (DNS) and Network Information Service(NIS). The particular naming services(s) being used is <strong>by default the local machine configured one</strong>. For any host name, its corresponding IP address is returned. <sup><a href="http://docs.oracle.com/javase/7/docs/api/java/net/InetAddress.html" rel="noreferrer">[source]</a></sup></p>
  </blockquote>
  
  <p>How can we configure this behavior without modifying the local machine's default hostname resolver?</p>
  
  <p>For example, is there anyway to configure <a href="http://docs.oracle.com/javase/7/docs/api/java/net/InetAddress.html" rel="noreferrer">java.net.InetAddress</a> such that it resolves host names through OpenDNS (208.67.222.222, 208.67.220.220) or Google Public DNS (2001:4860:4860::8888, 2001:4860:4860::8844)?</p>
  
  <p>Or is the only solution to explicitly create DNS packet requests, send them to the servers through either <a href="http://docs.oracle.com/javase/7/docs/api/java/net/DatagramSocket.html" rel="noreferrer">java.net.DatagramSocket</a> or <a href="http://docs.oracle.com/javase/7/docs/api/java/net/Socket.html" rel="noreferrer">java.net.Socket</a>, and parse the responses?</p>