Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 14946 - /etc/init.d/hostname includes domainname in hostname
Summary: /etc/init.d/hostname includes domainname in hostname
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: [OLD] Core system (show other bugs)
Hardware: All All
: High normal (vote)
Assignee: Martin Schlemmer (RETIRED)
URL:
Whiteboard:
Keywords:
: 20352 (view as bug list)
Depends on:
Blocks:
 
Reported: 2003-02-01 22:55 UTC by Shevek
Modified: 2004-11-09 21:07 UTC (History)
6 users (show)

See Also:
Package list:
Runtime testing required: ---


Attachments
/etc/init.d/hostname (hostname,1.10 KB, text/plain)
2003-02-02 05:15 UTC, Martin Schlemmer (RETIRED)
Details
hostname (hostname,1.41 KB, text/plain)
2003-04-16 20:06 UTC, Jesús P Rey (Chuso)
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Shevek 2003-02-01 22:55:31 UTC
/etc/init.d/hostname should use
$(cat /etc/hostname | cut -f 1 -d .)
for the value of $myhost, and
$(cat /etc/hostname | cut -f 2- -d ._)
to set domainname. Setting hostname to the whole show is wrong.

Reproducible: Always
Steps to Reproduce:
1.
2.
3.
Comment 1 Martin Schlemmer (RETIRED) gentoo-dev 2003-02-02 05:15:27 UTC
Created attachment 7843 [details]
/etc/init.d/hostname

Have a look if this one is fine, thanks.
Comment 2 Martin Schlemmer (RETIRED) gentoo-dev 2003-02-03 13:59:14 UTC
No offense, but this breaks DNS resolving among things for me.

Guys, can you have a look please ?  Ill admit im not the best of
network guru out there.
Comment 3 SpanKY gentoo-dev 2003-02-03 15:57:48 UTC
usually you have the domain in your /etc/resolv.conf and you have the host actually 
defined in your dns records or in your /etc/hosts ... 
Comment 4 Martin Schlemmer (RETIRED) gentoo-dev 2003-02-28 10:10:46 UTC
Right.  Ok, I want to resolve this ... Mike, everything looks ok for you ?
Should we export a DOMAINNAME as welL ?
Comment 5 Brandon Low (RETIRED) gentoo-dev 2003-03-14 11:40:32 UTC
problem: this breaks the default postfix configuration.  It uses "gethostname" and expects a fully qualified domain name ( After using the new script I rebooted upon reboot, my mailserver started rejecting all mail as invalid relay, it was a good thing I was logwatching at the time for other reasons. )  Shouldn't hostname be fully qualified?
Comment 6 Shevek 2003-03-14 12:05:03 UTC
None of the Linux systems (RH, Slack, etc) I have seen returns the entire hostname with domainname from gethostname.

On the other hand, Solaris 5.8 does. I have nothing else booted at the moment.

I think sendmail pulls some stunt. See the (commented out) entry in the config file for the $j macro.
Comment 7 Martin Schlemmer (RETIRED) gentoo-dev 2003-04-06 11:01:30 UTC
I have a few bugs because of this change.  Is there a known fix ?  How should
we treat them ?
Comment 8 Stefan Förster 2003-04-12 05:59:40 UTC
I don't know exactly how to fix this, but it is perfectly OK that "gethostname" does _not_ return a name including a domain part. A systems FQDN is defined as the resolved name returned by "gethostbyname" called for the hostname "gethostname" returns. Of course, for this to work there needs to be an entry like "192.168.0.1 host.fqdn host" in /etc/hosts or you need DNS/NIS up and working.

If postfix does really use only gehtosname to get a FQDN, I propose it't time for asking a question on postfix-users or perhaps look at other distributions if their postfix-sources are patched.

Setting the hostname could be simplified to writing only the unqualified hostname to /etc/hostname and only calling "hostname --file /etc/hostname". No, this should _not_ break stuff for carefully programmed applications.

Correct me if I'm telling bullshit.
Comment 9 Seemant Kulleen (RETIRED) gentoo-dev 2003-04-12 06:28:25 UTC
Grant, thoughts?
Comment 10 Stefan Förster 2003-04-12 06:37:40 UTC
Please do also have a look at bugs 18158 and 18801. These problems derive from errors in the name resolution setup of particular users and are _not_ bugs in baselayout.
Comment 11 Shevek 2003-04-12 13:15:14 UTC
This is true but if domainname isn't set at all, other things break. This seems like a convenient place to set it.
Comment 12 Martin Schlemmer (RETIRED) gentoo-dev 2003-04-12 14:15:05 UTC
Ok, should we split it then to use /etc/hostname to set the hostname, and
/etc/domainname to set the domainname ?

Currently it will split whatever is in /etc/hostname ...
Comment 13 Shevek 2003-04-12 14:19:34 UTC
There isn't really any point is there? But then again there isn't any difference. Nothing else reads /etc/hostname. I only did it from one file because that's what Slackware did, except I think it called it /etc/HOSTNAME at the time.
Comment 14 Stefan Förster 2003-04-13 08:31:17 UTC
What do you mean with "if domainname isn't set at all, other things break"? And how do you _set_ a domainname? And why would you want to do that?
Comment 15 Shevek 2003-04-13 08:37:55 UTC
There is an equivalent call getdomainname which is used by some lazy programs to get the domain name of the machine, and an equivalent /bin/domainname. I don't remember what breaks since I got into the habit of setting it. I think it's mostly NIS related and I don't run NIS any more.
Comment 16 Stefan Förster 2003-04-13 09:31:34 UTC
/bin/domainname is indeed only used for setting the NIS-domainname, at least for the distributions I checked. If we do not perform the necessary steps to setup NIS in baselayout, I suggest we don't call /bin/domainname with the domain part stored in /etc/hostname but instead remove the domain part from /etc/hostname. I don't know how NIS setup works on Gentoo, but I strongly assume it uses a different file to store the NIS-domain (/etc/defaultdomain comes to my mind).
And again, domainname works nice even if you never set it explicitely - at least if your name resolution ist set up correctly.
BTW - is there any native German speaker who reads this and whom I may contact in German? As you might have noticed, I have some problems expressing these technical things in English, sorry guys.
Comment 17 Martin Schlemmer (RETIRED) gentoo-dev 2003-04-13 14:56:14 UTC
Try with C[XX]FLAGS="-march=i686 -O2 -pipe" .. or even just with -O2 ?
Comment 18 Martin Schlemmer (RETIRED) gentoo-dev 2003-04-13 14:57:04 UTC
Err, whoops, too many bugs open =)
Comment 19 Martin Schlemmer (RETIRED) gentoo-dev 2003-04-13 14:59:11 UTC
Ok, so how about just reverting like we did ?  Things that are broke, works,
and other things that are not, handle this as well ...
Comment 20 Jesús P Rey (Chuso) 2003-04-16 20:06:31 UTC
Created attachment 10770 [details]
hostname

I had found the same problem and modified the hostname file in this way and
worked.
Comment 21 Martin Schlemmer (RETIRED) gentoo-dev 2003-04-27 12:33:18 UTC
Ok, basically according to docs, etc, domainname is the NIS domain, and
I think we should not touch it if NIS is not setup properly, and this
the user will usually do (or this we rather expect to not make fatal
decisions).

What you guys are looking for, is what /bin/dnsdomainname gives.  And
this works fine if your /etc/hosts or /etc/resolv.conf is setup correctly.

Whatever stuff that borks thus because we set hostname properly, we need
to fix, or get upstream to fix.

I will thus remove the domainname stuff from the hostname rc-script.
Comment 22 Martin Schlemmer (RETIRED) gentoo-dev 2003-04-27 12:41:43 UTC
Anyhow, I think this can be closed, as the next baselayout will properly fix
this.
Comment 23 leon j. breedt 2003-05-01 23:18:23 UTC
i think /etc/init.d/hostname is trying to be more clever than it should be.
if i put the FQDN in /etc/hostname, thats what i want the hostname to be. if i put a single name in there, then obviously thats what i want it to be. please can we
revert to the original original behaviour from way back?

otherwise i have to hack the config files of my daemons expecting an FQDN. (postfix, apache, etc).
Comment 24 Martin Schlemmer (RETIRED) gentoo-dev 2003-05-04 03:20:17 UTC
Ok, I think I am going with last suggestion as well.

1) Leave domainname alone

2) Set whatever is in /etc/hostname, as the user might want to have a FQDN
   in there (even if its not the proper way).
Comment 25 Martin Schlemmer (RETIRED) gentoo-dev 2003-05-04 04:00:53 UTC
While we are at it, should we set the NIS/DNS domainname ?

What about this for a /etc/init.d/domainname:

---------------------------------------------------------
depend() {
    need checkroot hostname
}

checkconfig_nis() {
    if [ ! -f /etc/nisdomainname ] || [ -z "$(< /etc/nisdomainname)" ]
    then
#       eerror "You need to set /etc/nisdomainname to a valid NIS domainname"
        return 1
    fi
    return 0
}

checkconfig_dns() {
    if [ ! -f /etc/dnsdomainname ] || [ -z "$(< /etc/dnsdomainname)" ]
    then
#       eerror "You need to set /etc/nisdomainname to a valid DNS domainname"
        return 1
    fi
    return 0
}

start() {
    local mynisdomain=
    local mydnsdomain=
    local retval=0

    if checkconfig_nis
    then
        mynisdomain="$(< /etc/nisdomainname)"

        ebegin "Setting NIS domainname to ${mydomain}"
        /bin/domainname "${mydomain}"
        retval=$?
        eend ${retval} "Failed to set the domainname"

    fi

    if checkconfig_dns
    then
        mydnsdomain="$(< /etc/dnsdomainname)"

        [ ! -f /etc/resolv.conf ] && touch /etc/resolv.conf
        ebegin "Setting DNS domainname to ${mydomain}"
        gawk -v DOMAIN="${mydomain}" \
            'BEGIN { print "domain " DOMAIN }
             $0 !~ /^[[:space:]]*domain/ { print }' \
            /etc/resolv.conf > /etc/resolv.conf
        retval=$(($retval + $?))
        eend ${retval} "Failed to set the domainname"
    fi

    return ${retval}
}

Comment 26 Martin Schlemmer (RETIRED) gentoo-dev 2003-05-04 04:04:44 UTC
Err, skip that one:

----------------------------------------------------------------
depend() {
    need checkroot hostname
}

checkconfig_nis() {
    if [ ! -f /etc/nisdomainname ] || [ -z "$(< /etc/nisdomainname)" ]
    then
#       eerror "You need to set /etc/nisdomainname to a valid NIS domainname"
        return 1
    fi
    return 0
}

checkconfig_dns() {
    if [ ! -f /etc/dnsdomainname ] || [ -z "$(< /etc/dnsdomainname)" ]
    then
#       eerror "You need to set /etc/nisdomainname to a valid DNS domainname"
        return 1
    fi
    return 0
}

start() {
    local mynisdomain=
    local mydnsdomain=
    local retval=0

    if checkconfig_nis
    then
        mynisdomain="$(< /etc/nisdomainname)"

        ebegin "Setting NIS domainname to ${mynisdomain}"
        /bin/domainname "${mynisdomain}"
        retval=$?
        eend ${retval} "Failed to set the NIS domainname"

    fi

    if checkconfig_dns
    then
        mydnsdomain="$(< /etc/dnsdomainname)"

        [ ! -f /etc/resolv.conf ] && touch /etc/resolv.conf
        ebegin "Setting DNS domainname to ${mydnsdomain}"
        gawk -v DOMAIN="${mydnsdomain}" \
            'BEGIN { print "domain " DOMAIN }
             $0 !~ /^[[:space:]]*domain/ { print }' \
            /etc/resolv.conf > /etc/resolv.conf
        retval=$(($retval + $?))
        eend ${retval} "Failed to set the DNS domainname"
    fi

    return ${retval}
}
Comment 27 Martin Schlemmer (RETIRED) gentoo-dev 2003-05-04 04:45:25 UTC
The start() part needs to look like this:

----------------------------------------------------------
start() {
    local mynisdomain=
    local mydnsdomain=
    local retval=0
    local retval2=2

    if checkconfig_nis
    then
        mynisdomain="$(< /etc/nisdomainname)"

        ebegin "Setting NIS domainname to ${mynisdomain}"
        /bin/domainname "${mynisdomain}"
        retval=$?
        eend ${retval} "Failed to set the NIS domainname"

    fi

    if checkconfig_dns
    then
        mydnsdomain="$(< /etc/dnsdomainname)"

        [ ! -f /etc/resolv.conf ] && touch /etc/resolv.conf
        ebegin "Setting DNS domainname to ${mydnsdomain}"
        gawk -v DOMAIN="${mydnsdomain}" \
            'BEGIN { print "domain " DOMAIN }
             $0 !~ /^[[:space:]]*domain/ { print }' \
            /etc/resolv.conf > /etc/resolv.conf.new
        retval2=$?
        [ "${retval2}" -eq 0 ] \
            && (mv -f /etc/resolv.conf.new /etc/resolv.conf) \
            || (rm -f /etc/resolv.conf.new)
        eend ${retval2} "Failed to set the DNS domainname"
    fi

    retval=$((retval + retval2))

    return ${retval}
}
Comment 28 Martin Holzer (RETIRED) gentoo-dev 2003-05-05 11:45:51 UTC
*** Bug 20352 has been marked as a duplicate of this bug. ***
Comment 29 splite 2004-11-08 12:19:40 UTC
Why is retval2 initialized to 2 and not 0?  The way it is now, "/etc/init.d/domainname start" will fail without printing an error message if /etc/dnsdomainname doesn't exist, even if it successfully set the NIS domainname.
Comment 30 SpanKY gentoo-dev 2004-11-09 21:07:48 UTC
you're looking at an outdated init script

review cvs and/or baselayout-1.11.6