InetAddress.getByName fails behind proxy

I’m trying to resolve a host name to its’ corresponding IP.

My environment is a mac in a corporate network behind a proxy server, which is configured with a .pac file via the system preferences (automatic proxy configuration). So far everything is working fine and I can access resources inside and outside my corporate network.

Resolving hosts within my network works perfectly fine: InetAddress.getByName("host.local");

But when I use external host names, I get a UnknownHostException: InetAddress.getByName("");


Exception in thread "main"
    at Method)
    at Test.main(

(I’m a little bit surprised about Inet6AddressImpl here)

As far as I understand is InetAddress.getByName using the native mechanisms to resolve host names. So I don’t think that the error is caused by a missing proxy configuration within the java jvm.

But what else can it be, if everything else is working fine?

Some (maybe) useful additional information:

  • I’m using a MacBook, ifconfig shows the interfaces lo0, gif0, stf0, en0, fw0, en1 -> connected to the network, with ipv4 address.

  • nslookup on the console returns ** server can't find NXDOMAIN

  • The same code on a windows machine within the network produced the same Exception

Any ideas about the cause of this error? Or are there other ways to resolve host names in java?


Your corporate DNS server prevents you from resolving any Interent domain ( they probably do not want people browsing non-corporate context ).

This is supported by the fact that your nslookup query fails.

If you don’t have a vote on your corporate policy, and your development machine has to stay on your company premises, there is nothing that you can do.

Leave a Reply

Your email address will not be published. Required fields are marked *