[Users] No FQDN hostname for COS7/RHEL7 containers?

Scott Dowdle dowdle at montanalinux.org
Wed Aug 5 08:51:58 PDT 2015


Greetings,

----- Original Message -----
> Dear OpenVZ users,
> 
> I've got a questions concerning RHE7/CENTOS7 containers and the
> change in the script "/etc/vz/dists/scripts/redhat-set_hostname.sh"
> which comes with the newer versions of vzctl-core...
> 
> function set_hostname()
> {
>    local cfgfile="$1"
>    local var=$2
>    local val=$3
> 
>    [ -z "${val}" ] && return 0
> 
>    if [ -f /etc/hostname ]; then
>        # New style: RHEL7/Fedora15+
>        # Note hostname(5) says it should NOT be FQDN
>    val=${val%%.*}
>        echo "$val" > /etc/hostname
>    else
>        # "Classic" style
>        put_param "${cfgfile}" "${var}" "${val}"
>    fi
> 
>    hostname "${val}"
> }
> 
> change_hostname /etc/hosts "${HOSTNM}" "${IP_ADDR}"
> 
> 
> We've got some CENTOS7 containers for testing (running on Hardware
> with rhel6 openvz kernel at the moment) The hostname which should be
> FQDN in our environment is set to short hostname all the time. This
> happens because the file/etc/hostname exists in Centos 7.
> 
> The redhat-set_hostname.sh script changes our entry /etc/hostname  to
> short hostname...
> 
> When I read the man pages of my COS 7.1.1503 Container, I don't see
> any entry saying that hostname should not be FQDN....
> 
> Hostname(5) says that it is recommended but, not that it is a strict
> requirement...
> 
> DESCRIPTION
>       The /etc/hostname file configures the name of the local system
>       that is set during boot using the sethostname(2) system call.
>       It should contain a single newline-terminated hostname string.
>       The
>       hostname may be a free-form string up to 64 characters in
>       length; however, it is recommended that it consists only of
>       7-bit ASCII lower-case characters and no spaces or dots, and
>       limits itself to
>       the format allowed for DNS domain name labels, even though this
>       is not a strict requirement.
> 
> Hostname(1) says the following...
> 
> FILES
>       /etc/hostname  Historically  this  file  was supposed to only
>       contain the hostname and not the full canonical FQDN. Nowadays
>       most software is able to cope with a full FQDN here. This file
>       is read at
>       boot time by the system initialization scripts to set the
>       hostname.
> 
> So why do you prevent users from setting their hostname to
> fqdn-hostname with the change of the script above?

I have a RHEL6 physical host and it does not have an /etc/hostname file.  Where does the system get its hostname from then?  From /etc/sysconfig/network with a HOSTNAME= line and yes the FQDN is in there.

On RHEL7 it is different.  systemd provides a tool for setting the hostname (hostnamectl which stores the FQDN in /etc/hostname) and typically (on a physical host anyway) NetworkManager is used.  Since EL7 containers don't use NetworkManager, putting the hostname in /etc/sysconfig/network and/or /etc/hostname should work.  In fact shortly after CentOS 7.0 OS Template as released I filed a bug because hostnamectl putting it in /etc/hostname was being ignored so they fixed that.

So to answer your question, EL6 doesn't use /etc/hostname.

TYL,
-- 
Scott Dowdle
704 Church Street
Belgrade, MT 59714
(406)388-0827 [home]
(406)994-3931 [work]


More information about the Users mailing list