Join the community today
Become a Member

Install CentOS 7 - Hostname Changes after Reboot

Discussion in 'Install & Upgrades or Pre-Install Questions' started by nqservices, Jun 17, 2016.

  1. nqservices

    nqservices Member

    65
    13
    8
    Jun 17, 2016
    Ratings:
    +27
    Local Time:
    6:27 AM
    1.11.1
    MariaDB 10
    Hi,

    I'm having a problem with the Hostname of my CentOS 7 (64bit) - OpenVZ VPS server keeps changing the hostname after reboot.

    After CentminMOD installation i followed the instructions of setting the Default Server Hostname as described at: Getting Started Guide - CentminMod.com LEMP Nginx web stack for CentOS

    Before making the changes, when typing "uname -n" the hostname showed just as: "mysubdomain"

    After making all the changes, when typing "uname -n" the hostname showed as: "mysubdomain.mydomain.com"

    The problem is that everytime i reboot / restart my VPS server, the hostname goes back to the default "mysubdomain" when it should be "mysubdomain.mydomain.com"

    Note: On my hosting provider control panel, the hostname for this server is set as: "mysubdomain.mydomain.com"

    Does anyone as experience this issue? Any idea on how to resolve it?

    Thanks
     
  2. eva2000

    eva2000 Administrator Staff Member

    30,938
    6,912
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +10,408
    Local Time:
    4:27 PM
    Nginx 1.13.x
    MariaDB 5.5
    The guide has different instructions for CentOS 7 versus 6 did you follow CentOS 7 ones?
     
  3. nqservices

    nqservices Member

    65
    13
    8
    Jun 17, 2016
    Ratings:
    +27
    Local Time:
    6:27 AM
    1.11.1
    MariaDB 10
    Hi,

    Yes i did use the CentOS 7 steps. All remains working properly until reboot the vps server.

    Any ideas?

    Thanks
     
  4. eva2000

    eva2000 Administrator Staff Member

    30,938
    6,912
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +10,408
    Local Time:
    4:27 PM
    Nginx 1.13.x
    MariaDB 5.5
    Can you post the command you used as well as output for
    Code (Text):
    hostnamectl status

    and
    Code (Text):
    nmcli general hostname

    and
    Code (Text):
    cat /etc/hostname

    and
    Code (Text):
    cat /etc/cloud/cloud.cfg

    Might want to use CODE tags for code How to use forum BBCODE code tags :)
     
    Last edited: Jun 17, 2016
  5. eva2000

    eva2000 Administrator Staff Member

    30,938
    6,912
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +10,408
    Local Time:
    4:27 PM
    Nginx 1.13.x
    MariaDB 5.5
    Also are you using Amazon EC2 ? Amazon EC2 Linux Static Hostname RHEL7 Centos7

    edit: oh openvz vps is not EC2 heh but some of EC2 linked suggested ways to set hostname to persist on reboot maybe relevant. Just remove the sudo command/word from commands suggested as Centmin Mod doesn't use sudo
     
  6. apidevlab

    apidevlab Member

    88
    30
    18
    Mar 22, 2016
    /dev/null
    Ratings:
    +54
    Local Time:
    6:27 AM
    1.11.1
    5.2.14-122
    You can also try re-starting network BEFORE reboot I have seen similar behaviour at times on some of my VPS boxes.

    Code (Text):
    /etc/init.d/network restart
     
    • Informative Informative x 1
  7. nqservices

    nqservices Member

    65
    13
    8
    Jun 17, 2016
    Ratings:
    +27
    Local Time:
    6:27 AM
    1.11.1
    MariaDB 10
    Hi all.

    Thanks for all the help! Bellow i leave my responses to all your questions:

    This are the current results with the proper hoostname setup:

    [root@subdomain ~]# hostnamectl status
    Static hostname: subdomain.domain.com
    Icon name: computer-container
    Chassis: container
    Machine ID: 22ca1661401845c8935f2d08d130acd0
    Boot ID: 53040c02424a4164aefce8aa112b0065
    Virtualization: openvz
    Operating System: CentOS Linux 7 (Core)
    CPE OS Name: cpe:/o:centos:centos:7
    Kernel: Linux 2.6.32-042stab113.12
    Architecture: x86-64
    [root@subdomain ~]# nmcli general hostname
    -bash: nmcli: command not found
    [root@subdomain ~]# cat /etc/hostname
    subdomain.domain.com
    [root@subdomain ~]# cat /etc/cloud/cloud.cfg
    cat: /etc/cloud/cloud.cfg: No such file or directory
    [root@subdomain ~]#

    This are the results after reboot is made (you can see hostname changed to only "subdomain"):

    [root@subdomain ~]# hostnamectl status
    Static hostname: subdomain
    Icon name: computer-container
    Chassis: container
    Machine ID: 22ca1661401845c8935f2d08d130acd0
    Boot ID: 53040c02424a4164aefce8aa112b0065
    Virtualization: openvz
    Operating System: CentOS Linux 7 (Core)
    CPE OS Name: cpe:/o:centos:centos:7
    Kernel: Linux 2.6.32-042stab113.12
    Architecture: x86-64
    [root@subdomain ~]# nmcli general hostname
    -bash: nmcli: command not found
    [root@subdomain ~]# cat /etc/hostname
    subdomain
    [root@subdomain ~]# cat /etc/cloud/cloud.cfg
    cat: /etc/cloud/cloud.cfg: No such file or directory
    [root@subdomain ~]#


    Im not using Amaxzon EC2. Im using Time4VPS.eu that uses OpenVZ

    Do you mean, in this order: make the hostname change > restart the network > reboot vps server? I have try that now and after reboot, the hostname changed again to just "subdomain".

    ----

    Just one final information to say that after reboot the only place the hostname seems not to be saved is when i go to nano -w /etc/hostname that shows just the subdomain and i have to add the domain.

    All the following / other steps i do not need to make because it's all set with new hostname.

    Thanks
     
    Last edited: Jun 18, 2016
  8. eva2000

    eva2000 Administrator Staff Member

    30,938
    6,912
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +10,408
    Local Time:
    4:27 PM
    Nginx 1.13.x
    MariaDB 5.5
    you using solusvm control panel with web host ? what is the set hostname there when you ordered vps ? have you tried asking their support to see if they are doing something different for their setups ?

    what about output for
    Code (Text):
    cat /etc/hosts
    
     
  9. eva2000

    eva2000 Administrator Staff Member

    30,938
    6,912
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +10,408
    Local Time:
    4:27 PM
    Nginx 1.13.x
    MariaDB 5.5
    sounds like their do something funky with their control panel Getting Started with our Clients Portal [VPS] - Time4VPS Community
    so it's fixed ??
     
  10. nqservices

    nqservices Member

    65
    13
    8
    Jun 17, 2016
    Ratings:
    +27
    Local Time:
    6:27 AM
    1.11.1
    MariaDB 10
    Hi eva2000,

    I will contact Time4VPS support about this. Bellow i leave you with the results of the cat /etc/hosts:

    [root@subdomain ~]# cat /etc/hosts
    127.0.0.1 localhost.localdomain localhost localhost4.localdomain4 localhost4
    # Auto-generated hostname. Please do not remove this comment.
    XXX.XXX.XX.XX subdomain.domain.com subdomain
    ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
    [root@subdomain ~]#
    ----

    Thanks
     
  11. nqservices

    nqservices Member

    65
    13
    8
    Jun 17, 2016
    Ratings:
    +27
    Local Time:
    6:27 AM
    1.11.1
    MariaDB 10
    No is not fixed. On their control panel i had already setup the correct hostname as: subdomain.domain.com before start the CentOS installation.

    I will contact Time4VPS support team about this.

    Thanks
     
    Last edited: Jun 18, 2016
  12. eva2000

    eva2000 Administrator Staff Member

    30,938
    6,912
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +10,408
    Local Time:
    4:27 PM
    Nginx 1.13.x
    MariaDB 5.5
    k.. still suggestions at Amazon EC2 Linux Static Hostname RHEL7 Centos7 are relevant too
     
  13. nqservices

    nqservices Member

    65
    13
    8
    Jun 17, 2016
    Ratings:
    +27
    Local Time:
    6:27 AM
    1.11.1
    MariaDB 10
    Hi eva2000,

    Thanks for the advise. I try to change the files as you said and then reboot the server. The hostname problem is still not resolved.

    Bellow i leave you copy/paste so you can see how my files are now:

    /etc/hosts

    127.0.0.1 localhost.localdomain localhost localhost4.localdomain4 persistent_host_name localhost4
    # Auto-generated hostname. Please do not remove this comment.
    XXX.XXX.XX.XX subdomain.mydomain.com subdomain
    ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6

    /etc/sysconfig/network

    NETWORKING="yes"
    GATEWAYDEV="venet0"

    NETWORKING_IPV6=no
    HOSTNAME=persistent_host_name

    ---

    I still waiting from a response from my hosting support team about this.

    Thanks
     
  14. eva2000

    eva2000 Administrator Staff Member

    30,938
    6,912
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +10,408
    Local Time:
    4:27 PM
    Nginx 1.13.x
    MariaDB 5.5
    try instead for 1st line
    Code (Text):
    127.0.0.1 persistent_host_name localhost.localdomain localhost localhost4.localdomain4 localhost4
     
  15. apidevlab

    apidevlab Member

    88
    30
    18
    Mar 22, 2016
    /dev/null
    Ratings:
    +54
    Local Time:
    6:27 AM
    1.11.1
    5.2.14-122
    Got to say I am stumped, I have 1 VPS with Time4vps (running their customised 'filer' OS which is based on Cento6 I believe) I imagine the XXX.XXX.XX.XX subdomain.mydomain.com subdomain is your IP / domain yes?

    If so that all seems correct, so Time4vps will probably need to assist. As an alternative you can simply setup a DNS record (A & AAAA) and point to the server IP?
     
  16. eva2000

    eva2000 Administrator Staff Member

    30,938
    6,912
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +10,408
    Local Time:
    4:27 PM
    Nginx 1.13.x
    MariaDB 5.5
    you have to do that anyway as per Getting Started Guide step 1
     
  17. nqservices

    nqservices Member

    65
    13
    8
    Jun 17, 2016
    Ratings:
    +27
    Local Time:
    6:27 AM
    1.11.1
    MariaDB 10
    Hi,

    So the change you are saying is just on the "persistent_host_name" order on line? It must be placed on the beginning of the line?

    Im asking this because i do not see any other change and i think when i first added the "persistent_host_name" record it was on the beginning of the line, but it seems that after reboot the server the "persistent_host_name" was automatic moved to the position before the "localhost4" word.

    So i just to change the order from:
    127.0.0.1 localhost.localdomain localhost localhost4.localdomain4 persistent_host_name localhost4
    to
    127.0.0.1 persistent_host_name localhost.localdomain localhost localhost4.localdomain4 localhost4
    ---
    Thanks
     
  18. nqservices

    nqservices Member

    65
    13
    8
    Jun 17, 2016
    Ratings:
    +27
    Local Time:
    6:27 AM
    1.11.1
    MariaDB 10
    Hi,

    You said you are also hosted with Time4VPS and running CentOS 6, correct? Don't you have the same problem with hostname after reboot?

    Also, do you have any server with Time4VPS running CentOS 7? My VPS is running CentOS 7 + Minimal OS Config ( as described at: Make minimal OS - Time4VPS Community )

    The XXX.XXX.XX.XX is mask of my ip address and subdomain.mydomain.com is also just a mask, for security reasons. And about the A Record pointed to my server hostname is already setup.

    Thanks
     
  19. eva2000

    eva2000 Administrator Staff Member

    30,938
    6,912
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +10,408
    Local Time:
    4:27 PM
    Nginx 1.13.x
    MariaDB 5.5
    yeah the order
     
  20. eva2000

    eva2000 Administrator Staff Member

    30,938
    6,912
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +10,408
    Local Time:
    4:27 PM
    Nginx 1.13.x
    MariaDB 5.5
    what's contents and output of these commands ?
    Code (Text):
    cat /etc/sysconfig/network-scripts/ifcfg-venet0
    cat /etc/sysconfig/network-scripts/ifcfg-venet0:0
    cat /etc/sysconfig/network-scripts/ifcfg-venet0:1