Our application (RHEL 5/c++) uses the hostid as returned by gethostid for logging purposes. For some reason, the primary DNS server of the local network environment went offline. This resulted in massive problems in gethostid: The function call hangs for more than 60s, which lead to internal timeouts in our application. A call to hostid on the commandline also didn't return after several minutes. Once the DNS server was up again, the timeouts/problems both in the application and the hostid commandline tool disappeared.
My question is: How do I prevent gethostid from making DNS lookups? There`re some boundary conditions to the answer:
- The file
/etc/hostidmust not exist. - Calling
sethostidis not allowed. - Changing
/etc/hostsis not possible.
I'm astonished this happens at all. As I understand gethostid it works like this:
- Return the value of the last
sethostidif it has been set manually. - Return hostid form /etc/hostid if the file exists.
- Return the primary IP of the host if set.
- Fail for other cases.
I don`t see the need for a DNS query.
To verify, that gethostid actually is dependend on a working DNS server, try this:
- As root create/change your /etc/reslov.conf so it contains only invalid
nameserverentries. - Call
hostidon the commandline.
On my debian/squeeze installation this results in a hostid of 00000000 without any hangs. I assume the RedHat-version of hostid is different/older and results hangs.
/etc/nsswitch.confcontainshosts: files dns. The hostname of the primary IP of the system is not in/etc/hosts. This is by desing and a customer requirement.dnsfrom/etc/nsswitch.confan acceptable solution?