|
Bugzilla – Full Text Bug Listing |
| Summary: | hostname -s in /etc/profile causes DNS timeouts | ||
|---|---|---|---|
| Product: | [openSUSE] openSUSE 11.0 | Reporter: | Ludwig Nussel <lnussel> |
| Component: | Other | Assignee: | Dr. Werner Fink <werner> |
| Status: | RESOLVED FIXED | QA Contact: | E-mail List <qa-bugs> |
| Severity: | Normal | ||
| Priority: | P5 - None | CC: | b.eckenfels, mmeeks |
| Version: | Beta 1 | ||
| Target Milestone: | --- | ||
| Hardware: | Other | ||
| OS: | Other | ||
| Whiteboard: | |||
| Found By: | --- | Services Priority: | |
| Business Priority: | Blocker: | --- | |
| Marketing QA Status: | --- | IT Deployment: | --- |
|
Description
Ludwig Nussel
2008-05-05 09:44:50 UTC
Bad idea. We could use /proc/sys/kernel/hostname but nevertheless the resolver should prefer local data instead of running into timeouts. This discussion was hold a few years ago and the result was to use /etc/hosts before running into DNS timeout. Why this has changed now? The point is that having hostname resolving to localnet address in /etc/hosts is now regarded as ugly hack and we'd like to get rid of it. (Well, I'm personally not sure if this is the best approach but there's nothing harmful about it either.) Still, why is hostname -s even _calling_ resolver? It doesn't for me on 10.3 and I can see no reason why should it. (Sorry, I meant that there's nothing harmful about getting rid of useless self-resolving; I still think getting rid of the hostname record in /etc/hosts is risky since too many apps seem to depend on it.) Beside the called resolver from `/bin/hostname -s' the bash does use the variable HOSTNAME which is the full qualified domain name of the node. That may also provide a second timeout problem as the bash uses gethostname(2). gethostname(2) does not trigger resolver at all, there's no reason for it to be so - it just extracts the hostname from struct coming from the uname(2) syscall. The intention of this bug report is to get rid of a useless DNS roundtrip. It caught my attention due to the mentioned other bug report but is independent of that. HOST=${HOSTNAME%%.*} instead of that hostname -s call should suffice.
This is what /bin/hostname -s does for comparison:
gethostname(hname, sizeof(hname));
...
if (!(hp = gethostbyname(hname))) {
herror(program_name);
exit(1);
}
...
if (!(p = strchr(hp->h_name, '.')) && (c == 'd'))
return;
...
switch (c) {
...
case 's':
if (p != NULL)
*p = '\0';
printf("%s\n", hp->h_name);
break;
ie it tries to resolve the own hostname and then remove anything after the first dot.
Oh, indeed, I must've overlooked it before but it does this in 10.3 too... Any idea why is it doing the self-resolve step? No idea. It makes a difference if your hostname is actually the CNAME of another hostname. I don't know whether or not that is a useful configuration :-) Anyways, I still don't think /etc/profile should call hostname -s What is wrong with
-s, --short
Display the short host name. This is the host name cut at the
first dot.
of /bin/hostname?
Nothing is wrong with that. It just keeps secret that -s causes a dns lookup. RedHat has therefore added a patch to make that clear: http://cvs.fedoraproject.org/viewcvs/rpms/net-tools/devel/net-tools-1.60-hostname_man.patch?rev=1.2&view=auto Ok, an alternative fix would be to patch away that dns lookup in /bin/hostname :-) Use now `/bin/uname -n' (In reply to comment #12) > Use now `/bin/uname -n' Just a short note: instead of "uname -n" you can use "hostname". When you not specify a parameter it dies no lookup. For BOTH commands it might return a qualified name (containing dots). (we currently discussing net-tool's hostname -s behaviour on net-tools-devel@sf because it differs from debian/fedore hostname command which has removed the gethostbyname() call for -s). https://sourceforge.net/p/net-tools/mailman/net-tools-devel/ |