How to add permanent /etc/hosts entries ?

Discussion in 'Networking' started by jcesarotero, Aug 30, 2008.

  1. jcesarotero

    jcesarotero

    Joined:
    Aug 30, 2008
    Messages:
    1
    Likes Received:
    0
    Hello :

    My question is about Acer Aspire One Linux Version.

    If I add new entries to /etc/hosts file then I can ping, telnet, ftp to hosts added manually.
    But when I shutdown Aspire One, and boot again, /etc/hosts contents resets to only "localhost" entries (127.0.0.1) and loose all entries added manually.

    Must I write additional entries to any other file instead of /etc/hosts file, and Aspire One will add this entries on every boot ?.
    How can I prevent /etc/hosts to be overwriten on every boot ?.

    Thanks in advance.

    Cesar Otero
    (SPAIN)
     
    jcesarotero, Aug 30, 2008
    #1
  2. jcesarotero

    irober02

    Joined:
    Sep 16, 2008
    Messages:
    4
    Likes Received:
    0
    I'd like to know this too...
     
    irober02, Sep 18, 2008
    #2
  3. jcesarotero

    kevin

    Joined:
    Sep 18, 2008
    Messages:
    274
    Likes Received:
    0
    I think this might be a bug in the NetworkManager app. It's been reported for other Linux distributions as well.

    I can't think of an elegant fix, apart from getting a later NetworkManager (if it is even fixed). An inelegant fix would be to write a little script that waiting for (say) one minute, then overwrote /etc/hosts with a file of your choice. Then you could have it launched from /etc/rc.local or something. But the timings could be quite sensitive -- I don't know exactly when /etc/hosts gets munged.
     
    kevin, Sep 18, 2008
    #3
  4. jcesarotero

    daldred

    Joined:
    Aug 25, 2008
    Messages:
    887
    Likes Received:
    0
    The One rewrites its /etc/hosts on startup as a result of scripts in the /etc/rc* sort of area. I've succeeded in hacking out the bits causing the trouble, but am not at my machine at the moment; I'll try to remember exactly what needed doing later on and post something (not a lot of free time this evening, though...)
     
    daldred, Sep 18, 2008
    #4
  5. jcesarotero

    irober02

    Joined:
    Sep 16, 2008
    Messages:
    4
    Likes Received:
    0
    Does anybody have any idea of the thinking behind this seemingly rogue behaviour. It seems crazy. Someone must have thought it a good idea...
     
    irober02, Sep 18, 2008
    #5
  6. jcesarotero

    rbil

    Joined:
    Aug 14, 2008
    Messages:
    730
    Likes Received:
    0
    Location:
    The Wet Coast, Canada
    Has anyone replaced nm with wicd? Does it work on the AA? Seems to be the solution of choice in other distros.

    Cheers.
     
    rbil, Sep 19, 2008
    #6
  7. jcesarotero

    daldred

    Joined:
    Aug 25, 2008
    Messages:
    887
    Likes Received:
    0
    OK, here's what I am fairly sure fixed it for me!

    We're setting things up so that the One is called hhhh.dddd where hhhh is your desired hostname for the One, and dddd your domain name. I don't think the One is going to be bothered whether you set a domain name, but I wanted it set for other reasons.

    All of this needs doing as root; I recommend backing up any files before changing them. I'm assuming reasonable Linux knowledge (on the basis that if you know why you might want a normal /etc/hosts file you probably aren't a linux newbie!)

    1. In /etc/rc.d/rc.5 - comment out the stanza which sets the hostname and insert the line "/bin/hostname hhhh" immediately after it. The lines you want to comment out start with "#Set the Hostname" and end with "/bin/hostname LINPUS"

    2. In /etc/sysconfig/network, change the HOSTNAME line to "HOSTNAME hhhh"

    3. in /etc/HOSTNAME, the only line should read "hhhh.dddd"

    4. create your own /etc/hosts as required

    5. Sacrifice a virtual chicken to the great god Linpus, and reboot :cool:

    Someone please try this and confirm that it works; if it does I'll make the instructions easier for less linux people and turn it into a HowTo.
     
    daldred, Sep 19, 2008
    #7
  8. jcesarotero

    kevin

    Joined:
    Sep 18, 2008
    Messages:
    274
    Likes Received:
    0
    I couldn't find a chicken, so a sacrificed a jar of `Chicken Tonite' -- would that suffice, do you think? :)

    I think you have to be a bit careful here, or people who try this could get into a pickle. Management of /etc/hosts _should_ be dealt with by NetworkManager. Why? Because on a network where IPs are dynamically allocated, strictly speaking hostnames should also be dynamically allocated to match the IPs. That way hostnames and IPs are consistent across the whole network. If your computer doesn't have a network identity that exists outside itself -- i.e., it does not offer network services to other hosts -- then it's hostname _should_ remain as `localhost'. Strictly speaking you should not be changing it to a `real' hostname manually. That's because at all times Unix expects a machine to have a hostname that maps to an IP that is working (even if it's a loop-back like 127.0.0.1). All sorts of inter-process communication fails if this basic assumption is not met.

    So what _should_ happen is that, when you connect to a network that uses DHCP, the network manager should get your new hostname from the DHCP server and set it, get your new IP and set it, then rewrite /etc/hosts so that the new hostname and new IP match. Of course, it would then have to integrate into the /etc/hosts so written the static entries that you want. NetworkManager can't do any of this yet (or, at least, couldn't last time I checked). So anything you do to get around the problem is going to be a kludge of some sort, and the consequences need to be understood.

    If you set a hostname in the start-up scripts, then that hostname has to map onto a valid IP on a network whose interface is _up_ at boot time. Otherwise you get all sorts of problems at start-up. I noticed in particular the XFCE complained about bot being able to communicate using the specified host name. In practice, if you're using a DHCP-based setup, the only IP that will be up at boot time is the loopback IP, 127.0.0.1. What this means is that, in practice, you need to map the hostname hhhh.dddd to 127.0.0.1 in your /etc/hosts file.

    If you do this everything starts up OK, but it does mean that your selected hostname will always map onto a bogus address. And when the network interface finally comes up using DHCP you'll have an IP number that does not map onto any host name.

    Is this a problem? I suspect that for most people and most applications it probably isn't. But it does mean that any app that needs to know the IP number of the machine _on the network_ is not going to be able to find it from the hostname. None of the apps I run on the One are affected by this problem -- I imagine it is server-type processes that are going to break. But they're going to break anyway, because the stock Linpus way of handling host names is no better. Then again, because Linpus leaves your hostname as `localhost', then any app that really cares about this kind of stuff knows that you don't have a proper external IP and can at least warn the user.

    In short, I think your instructions could be ammended to say that you should modify /etc/hosts such that hhhh.ddd maps onto 127.0.0.1, and accept that you're breaking a basic principal of Unix networking by doing so. But until NetworkManager does hostname/IP mapping correctly, I don't think there is really a better approach than this, sadly.
     
    kevin, Sep 23, 2008
    #8
  9. jcesarotero

    nedfunnell

    Joined:
    Nov 8, 2008
    Messages:
    1
    Likes Received:
    0
    I'm having some trouble getting this to work. I get an error message on bootup that says that Xfce might not operate properly.

    My school's registration page apparently still sees my AA1 as 'localhost', although it reports the name as '10'. IT said this is probably because localhost is common. Notably, the registration page has this to say:

    - Make sure your workgroup is set to RESNET.

    -*nix users: If your computer name listed above is shown as an ip address, it mean that you are not passing the hostname in your DHCP request. See the documentation in your OS in order to resolve this issue.

    Any ideas?
    Thanks!
     
    nedfunnell, Nov 8, 2008
    #9
  10. jcesarotero

    zyberteq

    Joined:
    Nov 7, 2008
    Messages:
    1
    Likes Received:
    0
    i only changed the file: /etc/sysconfig/network
    there i changed HOSTNAME=localhost.mydomain.com to my preferred AAO hostname

    the rc.5 script reads this file in setting the hostname and related files, so i figured just changing above line was the safest.
    now i also don't get the error msg with xfce.

    maybe there's a better way because my hostname isn't announced to the DHCP server. so i'll try some other stuff but my linux knowledge is still limited
     
    zyberteq, Nov 11, 2008
    #10
  11. jcesarotero

    chupachups

    Joined:
    Nov 24, 2008
    Messages:
    41
    Likes Received:
    0
    not sure if this is related to what you want to do, but I've also been trying to get the rest of my home network to recognise my ONE by its hostname, and visa versa - mainly windows xp and windows 2000 machines

    I've gone through changing all the stuff I could find - I believe /etc/hosts is overwriten on bootup, and is driven by whats in /etc/sysconfig/network

    However despite all the things I've done, I still couldn't get the ONE to broadcast its hostname to the router during DHCP handshaking, where it shows up as "unknown....*****"

    But in my router, it looks like it is possible to associate a hostname with a MAC address, so when my ONE connects and shows up as "unknown......*****", I changed this once, and now the rest of the network can ping the ONE using its hostname

    Similarly, as my router recognises the windows hostnames, my ONE can ping the windows machines without an entry in its /etc/hosts

    This is a bit of a workaround, until I become more competent, and find out how to get the ONE to broadcast it hostname - so if any kind soul has a proper resolution instead of a kludge, I'd be grateful
     
    chupachups, Dec 4, 2008
    #11
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.