How can I get InetAddress.getByName() to work through a proxy server?

Tim Rohaly

The static method InetAddress.getByName() uses the underlying OS's name service resolver to determine the return value. Configuration of the resolver, i.e. telling the resolver where and how to make name/IP associations, is up to you. This is outside the control of a Java application.

Common ways to do name resolution from behind a proxy/firewall are:
  • Set up your proxy/firewall to allow DNS packets (UDP port 53) to pass unhindered.
  • Don't use DNS lookup. You can configure your resolver to use a hosts table or some other naming service, like NIS.
  • Run your own DNS server within your proxy/firewall. You then need to configure your platform to resolve names from this server, which must be reachable without going through the proxy or firewall.
  • Use a SOCKS proxy. Here, you have to configure your platform to tunnel the DNS protocol through your SOCKS proxy. Since SOCKS 4 doesn't support UDP, you will need to use SOCKS 5. One way to perform this tunneling is by using the product mentioned in http://www.jguru.com/jguru/faq/view.jsp?EID=227532