# localhost / local IP confusion

## Abraxa

Hello fellow gentoo-ers,

I've recently run into a networking issue that was a little tough to track down. The situation is that an Eclipse plugin launches an external Qt application and tries to talk to it via UDP:

 *Quote:*   

> Eclipse plugin sends from 192.168.178.34:X to 127.0.0.1:20000
> 
> Qt program sends from 192.168.178.34:20000 to 192.168.178.34:X
> 
> ICMP msg appears, says 192.168.178.34:X is unreachable

 

The result is that the reply packets never arrive. 192.168.178.34 is my eth0 IP.

On a VM with Ubuntu, it looks like this:

 *Quote:*   

> Eclipse plugin sends from 127.0.0.1:X to 127.0.0.1:20000
> 
> Qt program sends from 127.0.0.1:20000 to 127.0.0.1:X

 

Here, everything works as intended and the programs can have a nice chat.

Now if I add the line "192.168.178.34 localhost" to /etc/hosts, the Eclipse plugin and the Qt program can talk on my system, too:

 *Quote:*   

> Eclipse plugin sends from 192.168.178.34:X to 192.168.178.34:20000
> 
> Qt program sends from 192.168.178.34:20000 to 192.168.178.34:X

 

While I do reckon that such a line does not belong, it makes sense if I assume the Eclipse plugin is looking up "localhost" in order to determine the IP to send to. But why would it send from my local IP instead of localhost to begin with? For the record, "127.0.0.1 localhost" has always been present in that file.

Does anyone have an idea what could be going on here? The fact that it works as intended on Ubuntu tells me that there must be a configuration issue or bug on my gentoo system.

----------

## NeddySeagoon

Abraxa,

Please post your /etc/hosts

----------

## Abraxa

Hello NeddySeagoon,

this is my /etc/hosts:

```
# /etc/hosts: Local Host Database

#

# This file describes a number of aliases-to-address mappings for the for 

# local hosts that share this file.

#

# In the presence of the domain name service or NIS, this file may not be 

# consulted at all; see /etc/host.conf for the resolution order.

#

# IPv4 and IPv6 localhost aliases

127.0.0.1      localhost

::1             localhost
```

After replacing 127.0.0.1 by 192.168.178.34, things start working.

Thanks for the assistance!

----------

## NeddySeagoon

Abraxa,

What's there is correct.  You need another entry

```
192.168.178.34   <hostname>
```

<hostname> is your PC hostname.

----------

## szatox

don't replace 127.0.0.1, it is supposed to be bound to localhost. Adding another line with your eth0 address and hostname seems to be a better idea.

What does `route -n` show?

What happens when you ping localhost?

Does eclipse or that plugin have any settings that allow it to force source IP rather than let system take care of that?

----------

## 666threesixes666

```

# IPv4 and IPv6 localhost aliases 

127.0.0.1      localhost 

::1             localhost

```

aliases as in your host name.  im pretty sure you could drop your ip address as an alias also.

ie 

```

# IPv4 and IPv6 localhost aliases 

127.0.0.1      localhost  <hostname>

::1             localhost  <hostname>

```

from mr neddy's post.

----------

