Hostname Inside Lxc Container

Home » CentOS-Virt » Hostname Inside Lxc Container
CentOS-Virt 3 Comments

Hi all,

I have installed a CentOS6 lxc guest under a Debian 8.x LXC host. All it is working ok but I can’t change the hostname for the CentOS6 lxc container (it is using the same hostname from Debian host). I have modifyed HOSTNAME under /etc/sysconfig/network and /etc/hosts file, but it doesn’t works.

Do I need to change anything else??

Thanks.

3 thoughts on - Hostname Inside Lxc Container

  • These Files only persist the hostname. To actually set it live you have to call “hostname “. Your shell prompt will not change unless you log out and log in again though simply executing “hostname” without parameters should output the correct name right away.

    Keep in mind though that setting the hostname in a container requires explicit support for the UTS namespace on the host:

    http://man7.org/linux/man-pages/man7/namespaces.7.html

    If the host doesn’t support the UTS namespace for its guests or this feature is not configured for the guest in question then setting the hostname in the guest is not possible.

    Regards,
    Dennis

  • Thanks Dennis. I have tried to fix using “hostname” command but after reboot, returns to be the same hostname as Debian host. Debian kernel has UTS enabled …