IBM Support

DNS Lookups in Java Fail with javax.naming.CommunicationException

Troubleshooting


Problem

This document describes a problem that could surface when a Java application uses JNDI to perform DNS lookups. There is a simple work-around to this problem.

Environment

IBM i; IBM i Java Development Kit

Diagnosing The Problem

A Java application using JNDI to perform DNS lookup might fail with the following exception:

javax.naming.CommunicationException: DNS error [Root exception is java.net.PortUnreachableException: ICMP Port Unreachable]; Remaining name: 'myserver.mycompany.com'    
      at com.sun.jndi.dns.DnsClient.query(DnsClient.java:295)
      at com.sun.jndi.dns.Resolver.query(Resolver.java:76)
      at com.sun.jndi.dns.DnsContext.c_getAttributes(DnsContext.java:425)
      at com.sun.jndi.toolkit.ctx.ComponentDirContext.p_getAttributes(ComponentDirContext.java:225)
      at com.sun.jndi.toolkit.ctx.PartialCompositeDirContext.getAttributes(PartialCompositeDirContext.java:133)
      at com.sun.jndi.toolkit.ctx.PartialCompositeDirContext.getAttributes(PartialCompositeDirContext.java:121)
      at javax.naming.directory.InitialDirContext.getAttributes(InitialDirContext.java:151)
      at DNSTest.main(DNSRequest.java:89)
   Caused by: java.net.PortUnreachableException: ICMP Port Unreachable
      at java.net.PlainDatagramSocketImpl.receive0(Native Method)
      at java.net.PlainDatagramSocketImpl.receive(PlainDatagramSocketImpl.java:164)
      at java.net.DatagramSocket.receive(DatagramSocket.java:724)
      at com.sun.jndi.dns.DnsClient.doUdpQuery(DnsClient.java:406)
      at com.sun.jndi.dns.DnsClient.query(DnsClient.java:198)
      ... 7 more

Resolving The Problem

Create a /etc/resolv.conf file and populate it with the proper DNS server information.

Example

search my.server.com server.com
domain my.server.com
nameserver 1.2.3.400
nameserver 1.2.3.500

Notes: The above is an example. The /etc/resolv.conf file should contain unique server name and DNS information pertaining to your TCP/IP configuration. It should also be noted that this problem is specific to the IBM Technology for Java JVM. This behavior is consistent with other platforms using the IBM Technology for Java JVM.

***Avoid trouble***: The /etc/resolv.conf file is required to have a CCSID of 819 (ASCII) or 1252 (ANSI). In addition, the end of line (EOL) character needs to be set as the "Line Feed" (*LF) character. You can use the 'EDTF STMF(/etc/resolv.conf)' CL command and press F15 to display the options screen which will allow you to view/change these values. Following is an example of what you should see:

Example
...
3. Change CCSID of file . . . . .     00819    Job CCSID: 00037
...
5. Stream file EOL option . . . .     *LF      *CR, *LF, *CRLF, *LFCR, *USRDFN

After changing the value of the option, you will need to specify the option number at the top next to "Selection" and press ENTER for the change to be implemented.

[{"Type":"MASTER","Line of Business":{"code":"LOB57","label":"Power"},"Business Unit":{"code":"BU058","label":"IBM Infrastructure w\/TPS"},"Product":{"code":"SWG60","label":"IBM i"},"Platform":[{"code":"PF012","label":"IBM i"}],"Version":"7.1.0"}]

Historical Number

555659091

Document Information

More support for:
IBM i

Software version:
7.1.0

Operating system(s):
IBM i

Document number:
686717

Modified date:
18 December 2019

UID

nas8N1012391

Manage My Notification Subscriptions