Results 1 to 5 of 5

Thread: Cant get IP by hostname

  1. #1
    Join Date
    Jun 2006
    Beans
    7

    Cant get IP by hostname

    If I run 'hostname -i' I will get 127.0.1.1

    I have some programs which requires that it knows its correct local IP.

    So that it can do RPC to another computer and have the callbacks return.

    As well it multicasts its presence announcing it's IP.

    I am assuming that because hostname -i returns 127.0.1.1 the program is announcing its IP as 127.0.1.1 which leads to problems.

    Is there a way to make ubuntu resolve the IP instead of loopback?

    I dont need a real IP, nat'ed is fine.

  2. #2
    Join Date
    Dec 2008
    Beans
    Hidden!
    Distro
    Ubuntu 14.04 Trusty Tahr

    Re: Cant get IP by hostname

    Quote Originally Posted by tdyer View Post
    If I run 'hostname -i' I will get 127.0.1.1

    I have some programs which requires that it knows its correct local IP.

    So that it can do RPC to another computer and have the callbacks return.

    As well it multicasts its presence announcing it's IP.

    I am assuming that because hostname -i returns 127.0.1.1 the program is announcing its IP as 127.0.1.1 which leads to problems.

    Is there a way to make ubuntu resolve the IP instead of loopback?

    I dont need a real IP, nat'ed is fine.

    I get the correct response.
    Code:
    bruce@malibu:~>hostname -i
    192.168.1.12
    bruce@malibu:~>
    The basic command gets.
    Code:
    bruce@malibu:~>hostname
    malibu
    bruce@malibu:~>
    Maybe your /etc/hosts file isn't correct.
    Mine is as follows.
    Code:
    bruce@malibu:~>cat /etc/hosts
    127.0.0.1 localhost
    192.168.1.12 malibu
    192.168.1.200 printer
    
    # 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
    ff02::3 ip6-allhosts
    bruce@malibu:~>

  3. #3
    Join Date
    Jan 2006
    Location
    Not heaven... Iowa
    Beans
    Hidden!
    Distro
    Ubuntu

    Re: Cant get IP by hostname

    Quote Originally Posted by tdyer View Post
    If I run 'hostname -i' I will get 127.0.1.1
    For what it's worth, my (pretty much stock) /etc/hosts file:
    Code:
    127.0.0.1 localhost
    127.0.1.1 DELLbox.Mynet DELLbox
    
    # 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
    ff02::3 ip6-allhosts
    (END)
    And yes, hostname -i also returns 127.0.1.1.

    But... one of my servers is configured:
    Code:
    127.0.0.1       localhost.Mynet   localhost
    192.168.1.2   server1.Mynet    server1
    And, hostname -i returns 192.168.1.2
    Last edited by Iowan; March 4th, 2009 at 01:13 AM.
    Linux User #415691 Ubuntu User #8629
    Iowa Team (LoCo): [Wiki] [Launchpad]
    IRC channel: #ubuntu-us-ia on irc.freenode.net

  4. #4
    Join Date
    Jun 2006
    Beans
    7

    Re: Cant get IP by hostname

    My machine has a staticly assigned IP address, but most others are assigned dynamically by DHCP,

    Is there any way to make it automatic? I just don't think I can expect people to manually edit their /etc/hosts file every morning.

    /etc/hosts
    Code:
    127.0.0.1 localhost
    127.0.1.1 scu0237
    # 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
    ff02::3 ip6-allhosts
    $hostname
    scu0237
    $hostname -i
    127.0.1.1

    any ideas?

  5. #5
    Join Date
    Dec 2008
    Beans
    Hidden!
    Distro
    Ubuntu 14.04 Trusty Tahr

    Re: Cant get IP by hostname

    Quote Originally Posted by tdyer View Post
    My machine has a staticly assigned IP address, but most others are assigned dynamically by DHCP,

    Is there any way to make it automatic? I just don't think I can expect people to manually edit their /etc/hosts file every morning.
    Yes you can. See here for instructions.

    /etc/hosts
    Code:
    127.0.0.1 localhost
    127.0.1.1 scu0237
    # 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
    ff02::3 ip6-allhosts
    $hostname
    scu0237
    $hostname -i
    127.0.1.1

    any ideas?
    All we are doing is providing a mapping between the hostname and an IP address. Everything in the 127.x.x.x range refers to the loopback address. This is the NIC (ethernet card) itself.

    We need to know your "statically assigned IP address" You can find that by using the command:
    Code:
    ifconfig -a
    My data looks like this:
    Code:
    bruce@malibu:~>ifconfig -a
    eth0      Link encap:Ethernet  HWaddr 00:04:76:CD:DD:E0  
              inet addr:192.168.1.12  Bcast:192.168.1.255  Mask:255.255.255.0
              inet6 addr: fe80::204:76ff:fecd:DDe0/64 Scope:Link
              UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
              RX packets:2467 errors:0 dropped:0 overruns:0 frame:0
              TX packets:2336 errors:0 dropped:0 overruns:0 carrier:0
              collisions:0 txqueuelen:1000 
              RX bytes:2571400 (2.4 MB)  TX bytes:258847 (252.7 KB)
              Interrupt:11 Base address:0x2000 
    
    lo        Link encap:Local Loopback  
              inet addr:127.0.0.1  Mask:255.0.0.0
              inet6 addr: ::1/128 Scope:Host
              UP LOOPBACK RUNNING  MTU:16436  Metric:1
              RX packets:0 errors:0 dropped:0 overruns:0 frame:0
              TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
              collisions:0 txqueuelen:0 
              RX bytes:0 (0.0 b)  TX bytes:0 (0.0 b)
    In the above example the eth0 address is the interface you need.

    The lo address is your loopback address. Not the one you need.

    Edit your hosts file and replace the 127.0.1.1 with the the eth0 address.

Bookmarks

Posting Permissions

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