2

after updating to Ubuntu 10.10, the hostname settings are no longer correct. The content of the /etc/hosts is modified at each startup to something like:

127.0.0.1       mariusbotis     localhost.localdomain   localhost
::1     mariusbotis     localhost6.localdomain6 localhost6
10.8.3.105      mariusbotis     mariusbotis.office

Do you have any idea how to get rid of the first two lines? Just editing them will not help: after the next restart, the lines are back there. The problem is that the network now resolve my hostname to 127.0.0.1, instead of the 10.8.3.105:

~:$ ping mariusbotis
PING mariusbotis (127.0.0.1) 56(84) bytes of data.
64 bytes from mariusbotis (127.0.0.1): icmp_req=1 ttl=64 time=0.022 ms
64 bytes from mariusbotis (127.0.0.1): icmp_req=2 ttl=64 time=0.023 ms
64 bytes from mariusbotis (127.0.0.1): icmp_req=3 ttl=64 time=0.021 ms
64 bytes from mariusbotis (127.0.0.1): icmp_req=4 ttl=64 time=0.022 ms

2 Answers 2

1

To add to the discussion, I just upgraded from Ubuntu 10.04 to Ubuntu 10.10 and I'm having a similar problem as botismarius. I'm developing web applications on my laptop and I'm using aliases in the /etc/hosts file that are used by apache2 as the virtual hostname.

The /etc/hosts file was not overwritten in 10.04 but it is now being overwritten in 10.10. I simply want to paste "test1.local" to the end of the localhost line but it gets lost every time I reboot.

Update: I figured out how to keep NetworkManager from overwriting the changes. Don't add aliases to the localhost line, add them to the "127.0.1.1 your-machine-name" line.

Jamie

2
  • interesting. I wonder why in this case a ping to your-machine-name does not respond from 127.0.1.1 (IP address that is from loopback interface too) Oct 14, 2010 at 19:27
  • NetworkManager is adding an entry at the top of the file with the DHCP assigned address and associates it with the host name. I'm assuming it picks up the first one it finds. Oct 15, 2010 at 18:17
2

This is actually expected and intended behavior. You do want to have connections from your own host to yourself go through the loopback interface (the interface connected to your own host) which by default has IP 127.0.0.1 (in IPv4) and ::1 (in IPv6). If your external network were down, you could not reach services on your own machine anymore and this includes, among others, also the X server and other daemons.

Note that the /etc/hosts file is only used on you own machine. If you have hosts files (or DNS) setup on other hosts in your network you will still reach your machine under the name "mariusbotis".

Maybe you could clarify why mariusbotis resolving to 127.0.0.1 is a problem for you.

[1] http://en.wikipedia.org/wiki/Hosts_file

6
  • The loopback (localhost) should be resolved to 127.0.0.1. I have an application that just does not work because of these settings, I am not sure yet why. Anyway, 127.x.y.z should be only the loopback address. Oct 12, 2010 at 15:24
  • 1
    It might be that your application is explicitly only listening on 10.8.3.105 and the associated network interface. You might be able to change the settings and make it listen on all interfaces instead. Can you share which application causes you trouble?
    – Tronic
    Oct 12, 2010 at 15:28
  • My application finds the hostname, resolve it to an IP and listens on that address (in my case, the application will listen to 127.0.0.1 which clearly will not be reachable from other computers). Unfortunately, I cannot change the behavior of the application... Oct 12, 2010 at 15:28
  • Do I understand correctly that the application finds the hostname automatically and does also the lookup of the IP by itself? Just some ideas: try not removing the whole line but just your hostname "mariusbotis" from the first line. If you use DHCP, that might rewrite the file -> change to static IP. But again, I would consider these hacks/workarounds..
    – Tronic
    Oct 12, 2010 at 16:03
  • Well, it is very strange that by default Ubuntu does this. Try on your machine to ping your hostname, does 127.0.0.1 respond to the request or another IP? In case something does not work as expected, the solution -if any- shouldn't be considered a hack. Oct 14, 2010 at 7:27

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .