newspaint

Documenting Problems That Were Difficult To Find The Answer To

Fixing Ubuntu Hosts File So CORBA Listener Knows The Right Address

The Problem

So the situation is this. I have a Java script that creates a “listener” (i.e. a server) in CORBA that will be communicated over another CORBA connection as the location to be connected to. In Wireshark I see this as as packet with the following fields:

Profile ID: TAG_INTERNET_IOP (0)
IIOP::Profile_host: 127.0.1.1
IIOP::Profile_port: 49170

Now this is no good. Any remote service that tries to connect to 127.0.1.1 will end up trying to communicate with itself (127.* is the loopback address).

The Solution

We need a way of letting Java CORBA figure out for itself what the IP address of the host we’re running our program on is.

The problem, in Ubuntu 12.04.1 at least, is that the /etc/hosts file contain the following entries by default (the problem line is highlighted in bold):

127.0.0.1       localhost
127.0.1.1       myserver.mydomain  myserver

# The following lines are desirable for IPv6 capable hosts
::1     ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters

What we need to do is comment out this 127.0.1.1 entry and replace it with the current IP address and uname of the host.

If, like me, you are connected by way of interface eth0 then you can perform the necessary change using the following one-liner:

MYNAME=`uname -n` \
MYIP=`ifconfig eth0 |perl -ne 'print $1 if m/:(\d+\.\d+\.\d+\.\d+)/'` \
perl -i.bak -pe "s/^(127.0.1.1.*$)/#\$1\\n\$ENV{MYIP} \$ENV{MYNAME}/" /etc/hosts

Result

This will result in a /etc/hosts file that will look something like the following:

127.0.0.1       localhost
#127.0.1.1      myserver.mydomain  myserver
10.191.22.14 myserver

# The following lines are desirable for IPv6 capable hosts
::1     ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: