Find the answer to your Linux question:
Results 1 to 2 of 2
Ok, I don't really understand all this, newbie to linux and all, but.. I think I need to update my /etc/hosts file so that there is always a line where ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    noc
    noc is offline
    Just Joined!
    Join Date
    Jul 2006
    Location
    Tampere, Finland
    Posts
    2

    how to update /etc/hosts when dynamic ip changes


    Ok, I don't really understand all this, newbie to linux and all, but..

    I think I need to update my /etc/hosts file so that there is always a line where 127.0.0.1 is mapped to what I think is my current ip address (I have a dynamic ip) in IPv6 format, like below..

    127.0.0.1 dnaXX-XXX

    how best make it happen? Updating a text file doesn't sound too elegant in the first place, there is a much more sophisticated way doing this? There was some talk about name servers in the /etc/conf comments..

    If you are interested why the need for this, I hit into a little bit of a problem with my Suse 10.1, as in java (5) a simple call to resolve the local host (InetAddress.getLocalHost()) results in an UnknownHostException: dnaXX-XXX. To me that dnaXX-XXX (where X's are numbers), which also reads in my console as the prompt, didn't look like an internet address I'm used to so I thought to myself it ought to be one of those IPv6 addresses. And If I've understood correctly what I've read so far that's excactly what it was and the problem is a linux jdk bug got something to do with IPv6. To make it all go away, I read the way to go is to disable IPv6 from the kernel (did that), start the java program with a property -Djava.net.preferIPv4Stack=true (tried), and finally, to check if /etc/hosts is as it should be. I had no idea what all the lines in my /etc/conf were supposed to mean so I just tested adding a line like above with the current address and it worked. Maybe you find out the problem in my /etc/hosts and I need not actually add a line but remove some? -I tried commenting all them ipv6 related lines out but that had no effect. The file reads as follows :

    127.0.0.1 localhost

    # special IPv6 addresses

    ::1 localhost ipv6-localhost ipv6-loopback

    fe00::0 ipv6-localnet

    ff00::0 ipv6-mcastprefix
    ff02::1 ipv6-allnodes
    ff02::2 ipv6-allrouters
    ff02::3 ipv6-allhosts
    127.0.0.2 linux-okdi.site linux-okdi

    Long post, srry. And thanks in advance..

  2. #2
    noc
    noc is offline
    Just Joined!
    Join Date
    Jul 2006
    Location
    Tampere, Finland
    Posts
    2
    Further, I think scripts in..

    /etc/sysconfig/network/if-up.d/

    ..will be called when an interface is brought up, down or is new, as in the ip has changed. This sounds like a good place for some script to edit the /etc/hosts? Initial testing shows, however, that these scripts wouldn't be called when I have knetworkmanager managing the network as is the case. This is true? Should I try and get rid of knetworkmanager, or would there be another way to edit the file as the ip changes or is it maybe indeed possible to make the hostname to be set in ipv4 format in the first place instead of ipv6? I THINK I have at least seen the shell bash prompt be in the ipv4 format sometimes..

    Any comments would be welcome..

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •