host $(/bin/hostname) differs from gethostbyname(HOSTNAME)



Can someone explain (roughly) the algorithm that the host command uses
to determine the IP address?

On my server, /etc/hosts maps 127.0.0.1 to HOSTNAME, and
gethostbyname(HOSTNAME) returns 127.0.0.1 as expected. However, the
host command, when given HOSTNAME, returns the actual IP address. Is
the host command bypassing /etc/hosts and/or not using gethostbyname?
Is the host command going directly to the DNS server to get the IP
address?

BTW, I'm trying to convince my sysadmin that /etc/hosts should not map
127.0.0.1 to HOSTNAME (unless the server is not on a network) because
of this exact problem, but he's not convinced because he's not seeing
any ill effects. Only my code, which uses gethostbyname(HOSTNAME), is
exhibiting the problem of finding the wrong IP address.

Thanks!

.



Relevant Pages

  • /usr/bin/host $(/bin/hostname) differs from gethostbyname(HOSTNAME)
    ... Can someone explain the algorithm that the host command uses ... On my server, /etc/hosts maps 127.0.0.1 to HOSTNAME, and ... host command, when given HOSTNAME, returns the actual IP address. ... Is the host command going directly to the DNS server to get the IP ...
    (comp.unix.programmer)
  • Re: Help w/ Not-booting Problem
    ... >No - setting the hostname is one element in the boot process. ... I have had a working system of RedHat Linux 7.2 for several months. ... >external DNS server on an adsl router! ... >You appear to have a networking problem. ...
    (comp.os.linux.misc)
  • Re: SMTP server for mass email
    ... server being blacklisted. ... listed in RHS blacklists. ... 'MX record for domain pointing to hostname + A record for hostname ... There's a common problem when outbound gateways behind the same ...
    (microsoft.public.inetserver.iis.smtp_nntp)
  • Re: DNS lookup delays
    ... > 127.0.0.1 localhost.localdomain localhost luminiferous luminiferous.aethernet ... You want to set your hostname, so the machine isn't trying to work it ... That sounds awfully like it's not using its own hosts file to work out ... >> to resolve them locally (via the hosts file, or your own DNS server). ...
    (linux.redhat.install)
  • Re: OEs DNS checking doesnt work
    ... If an IP address works, but a hostname does, the problem is ... probably with the interaction with the name server, ... to be sure outgoing mail now works. ... your ISP if that was intentional. ...
    (microsoft.public.windows.inetexplorer.ie6_outlookexpress)