Solving 'UnknownHostException' on Linux

Another tip for Ubuntu and Linux users this week. A few times I've had emails to the support inbox along these lines...

I have installed bliss on my Ubuntu laptop. The installation was successful and I could start bliss without errors on the console, however the webpage does not change from: I have it installed with Oracle Java version 8
HTTP ERROR: 503
Problem accessing /. Reason:

    Service Unavailable
Powered by Jetty://

This can actually have a few different causes, but the most common cause on Linux is an inability of the computer running bliss to resolve its own hostname. This doesn't just affect Ubuntu users; it can affect all Linux users depending on your configuration. Indeed, it affected VortexBox users for a while.

So how do you find out this is an issue? The first step is to work out what your hostname is. On the command line:

$ hostname
study-workstation

So study-workstation is the hostname. Now we can see if we can resolve that name by pinging it:

$ ping study-workstation
ping: unknown host study-workstation

Oh dear! We have no way of resolving the host name "study-workstation". You can double check this is the cause by looking in /tmp/bliss.log for UnknownHostException:

2015-02-11 19:27:54,272 (thread FelixStartLevel) WARN  FAILED LiftFilter: java.net.UnknownHostException: study-workstation:study-workstation: unknown error (AbstractLifeCycle.java:199)
java.net.UnknownHostException: study-workstation: study-workstation: unknown error

A simple solution for home/small office setups is to edit your /etc/hosts file to include an entry for the hostname. Here might be something like the default hosts file:

127.0.0.1       localhost

If we add in the hostname after the 127.0.0.1 line, that should allow us to resolve to the local machine (127.0.0.1 is a special IP address that means loop back to the local computer).

127.0.0.1       localhost study-workstation

Now:

$ ping study-workstation
PING study-workstation (127.0.0.1) 56(84) bytes of data.
64 bytes from study-workstation (127.0.0.1): icmp_seq=1 ttl=64 time=0.044 ms
64 bytes from study-workstation (127.0.0.1): icmp_seq=2 ttl=64 time=0.040 ms

That works! It also works for fully qualified names, for example study-workstation.example.com.

As a fallback, I wonder if it might be best to try to bind to localhost or 127.0.0.1?

Thanks to CS_McMahon for the image above.
tags: debian redhat dns

The Music Library Management blog

Dan Gravell

I'm Dan, the founder and programmer of bliss. I write bliss to solve my own problems with my digital music collection.