2

I have problem running java program which call InetAddress.getLocalHost as a non root user on a specific linux rhel machine. I tried running the program in another machine without any problem (either as a root or non root user).

Error:

at java.net.UnknownHostException: thebox: thebox: Temporary failure in name resolution
at java.net.InetAddress.getLocalHost(InetAddress.java:1473)

Code:

public class MyInetAddress {

    public static void main(String[] args) throws UnknownHostException {
        InetAddress Address = InetAddress.getLocalHost();
        System.out.println(Address);
    }
}

Environment:

# java -version
java version "1.7.0_55"
OpenJDK Runtime Environment (rhel-2.4.7.1.el6_5-x86_64 u55-b13)
OpenJDK 64-Bit Server VM (build 24.51-b03, mixed mode)

# uname -rmo
2.6.32-279.2.1.el6.x86_64 x86_64 GNU/Linux
Sully
  • 14,672
  • 5
  • 54
  • 79
user3737906
  • 89
  • 1
  • 9
  • "Thrown to indicate that the IP address of a host could not be determined". Check the DNS and make sure you can ping it – Sully Jun 15 '14 at 08:25
  • 1
    What does `hostname` return and do you see this name when you cat /etc/hosts? – laune Jun 15 '14 at 08:29
  • My bad ! I overlook the permission of folder /etc. Thanks to Hitham and laune for the time taken. I change the permission for /etc from 700 to 755 and the problem solved. I overlook the error after su to non user account ie **-bash: /etc/profile: Permission denied**. Proceed with hostname command which return **mybox**, and realize something wrong when i get **grep: /etc/hosts: Permission denied** when running `grep mybox /etc/hosts' ' – user3737906 Jun 15 '14 at 15:07

0 Answers0