-   Linux - Software (
-   -   Verify /etc/hosts usage and round robin in /etc/hosts (

MikeyCarter 06-24-2008 10:45 AM

Verify /etc/hosts usage and round robin in /etc/hosts
A while back my ISP threatened to shut me down because I was doing a DOS attack on their DNS.

Turns out that my various computers doing various monitoring scripts put a really high resolution rate on a single address. So to solve the problem I added started adding my more frequent dns pings in the /etc/hosts file.

So I have two questions:

Is there a way for me to verify which programs use the /etc/hosts? I noticed dig doesn't. Does ping? What about the hosts command?

Also there is one site which has a round robin on 4 IP's. My DNS cache and hosts currently can only cache one of the 4. Is there a way of specifying all 4 in the /etc/hosts file and have it used in a round robin fashion?

marozsas 06-24-2008 01:20 PM

Regarding for the first part of your question: Is there a way for me to verify which programs use the /etc/hosts?

As far as I known, all programs ask to "the resolver", a libc group of functions (gethostbyname, gethostbyaddress, etc, see man 3 GETHOSTBYNAME ) to resolve a string in an address and other related operations.

This group of functions may use several sources like /etc files, dns, nis, nis++, ldap, etc.
The main configuration file is /etc/nsswitch.conf. For the hosts related questions, mine is configured as follow:

hosts:      nisplus dns files
So, if the address was not resolved by NIS, then the resolver asks for DNS, and then looking at /etc/hosts.
Yours may be different.

The second part: multiple IPs for the same name; This is quite common and the DNS is aware about multiple answers.
For instance, a dig on returns 4 answers and all are cached. You don't need to take additional steps.

;; ANSWER SECTION:                335701        IN        CNAME        148        IN        A        148        IN        A        148        IN        A        148        IN        A

All times are GMT -5. The time now is 09:28 PM.