[CALUG] /etc/hosts not used?

Rajiv Gunja opn.src.rocks at gmail.com
Sun Mar 19 06:01:40 CST 2006


Aren't you missing or overlooking one key file which is used by host or
nslookup or gethostbyname?
/etc/nsswitch.conf.

Yes define all your network hosts and their ip-addresses in /etc/hosts.

Now edit your /etc/nsswitch.conf, the line which looks like this.

hosts:          files dns

change it to :

hosts:          files

Now no matter what command you do, all hosts will be resolved from your
/etc/hosts and not the DNS.

-GGR

---
Rajiv G Gunja
System Analyst / Engg
SUN / AIX / HPUX / Linux Admin
IM: AOL / Yahoo / MSN : ggvrsn


On 3/18/06, Jim Sansing <jjsansing at comcast.net> wrote:
>
> I haven't seen in this thread what you intend to use it for, so I
> don't know how much help this will be, but ping does what you
> want.  If you just need a simple command line utility, you could
> get one response and cut the hostname:
>
>   ping -c 1 -W 1 <ip_addr> | cut -f2,3 -d' ' | head -1
>
> If you need it in an application, grab the ping source code and
> see what they are doing (from the hosts man page, it looks like
> the resolver system call and I don't know if Perl has that function).
>
> Later . . .   Jim
>
>
> Eldon Ziegler wrote:
> >The perl statement printed foo, not the IP address. You're right that
> >what I want is some shell command ("host" or not) that will first
> >look in /etc/hosts and then use DNS to find an IP address.
> >
> >At 01:35 pm 3/18/2006, Jim Bauer wrote:
> >
> >>On Saturday 18 March 2006 07:12, Eldon Ziegler wrote:
> >>
> >>>I need a local host name to IP address association to override that
> >>>provided by DNS. However, after entering the new definition in
> >>>/etc/hosts the "host" command still returns the IP address from DNS.
> >>>I've tried in on Linux 2.6 (RedHat ES4) and 2.4 (RedHat 9.x).
> >>>
> >>>/etc/host.conf has "order hosts,bind". /etc/nsswitch.conf has "hosts:
> >>>files dns". Does some service need to be restarted? How do I get
> >>>/etc/hosts to override DNS?
> >>>
> >>I am fairly certain the host command only does DNS lookups.
> >>So it'll never look in /etc/hosts.
> >>
> >>I think you really want to know what does the gethostbyname() library
> >>routine will return?  Try this to find out (replacing 'foo' with what
> >>you want to lookup).
> >>
> >>perl -e '($x) = gethostbyname("foo"); print $x, "\n"'
> >>
> >>_______________________________________________
> >>Columbia, Maryland Linux User's Group (CALUG) mailing list
> >>CALUG Website: http://www.calug.com
> >>Email postings to: lug at calug.com
> >>Change your list subscription options:
> http://calug.com/mailman/listinfo/lug
> >>
> >
> >_______________________________________________
> >Columbia, Maryland Linux User's Group (CALUG) mailing list
> >CALUG Website: http://www.calug.com
> >Email postings to: lug at calug.com
> >Change your list subscription options:
> http://calug.com/mailman/listinfo/lug
> >
> >
> _______________________________________________
> Columbia, Maryland Linux User's Group (CALUG) mailing list
> CALUG Website: http://www.calug.com
> Email postings to: lug at calug.com
> Change your list subscription options:
> http://calug.com/mailman/listinfo/lug
>



--
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://calug.com/pipermail/lug/attachments/20060319/9f968403/attachment.html 


More information about the lug mailing list