Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

Hi can't seem to change the hostname on my centos 6.5 host. I am following the instructions I found here: http://www.rackspace.com/knowledge_center/article/centos-hostname-change

I set my /etc/hosts like so ...

    [root@mig-dev-006 ~]# cat /etc/hosts
    127.0.0.1   localhost localhost.localdomain 
    192.168.32.128  ost-dev-00.domain.com ost-dev-00
    192.168.32.129  ost-dev-01.domain.com ost-dev-01

... then I make my /etc/sysconfig/network file like so ...

    [root@mig-dev-006 ~]# cat /etc/sysconfig/network
    NETWORKING=yes
    HOSTNAME=ost-dev-00.domain.com
    NTPSERVERARGS=iburst

... then I run hostname like so ...

    [root@mig-dev-006 ~]# hostname ost-dev-00.domain.com

... and then I run bash and all seems well ...

    [root@mig-dev-006 ~]# bash

... but when I restart my network the old hostname comes back:

    [root@ost-dev-00 ~]# /etc/init.d/network restart
    Shutting down interface eth0:  Device state: 3 (disconnected)
                                                               [  OK  ]
    Shutting down loopback interface:                          [  OK  ]
    Bringing up loopback interface:                            [  OK  ]
    Bringing up interface eth0:  Active connection state: activating
    Active connection path: /org/freedesktop/NetworkManager/ActiveConnection/6
    state: activated
    Connection activated
                                                               [  OK  ]
    [root@ost-dev-00 ~]# bash
    [root@mig-dev-006 ~]# 

... I can't figure it out. What am I doing wrong here.

share|improve this question
    
Have you edited your /etc/hostname file? –  Anthon Jul 17 at 5:54
    
There isn't a /etc/hostname file. [root@smp-mig-dev-006 ~]# ls -l /etc/hostname outputs ls: cannot access /etc/hostname: No such file or directory –  Red Cricket Jul 17 at 5:56
    
Might be a Centos thing. What does your manpage tell you about the permanency of hostname somename, that it has a lasting effect? (if not why do you make that call?) –  Anthon Jul 17 at 5:59

2 Answers 2

up vote 7 down vote accepted

to change the hostname permanently, you need to change it in two places:

vi /etc/sysconfig/network
NETWORKING=yes
HOSTNAME=newHostName

and:

vi /etc/hosts
127.0.0.1 newHostName
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6

and then rebooting the system

share|improve this answer
    
At the end of this two changes add hostname newHostName, is not necessary to reboot I think –  Edakos Sep 19 at 21:01
    
@Edakos, no it is not necessary –  Networker Sep 19 at 21:07

From man hostname:

SET NAME
   When called with one argument or with the --file option, the  commands
   set  the  host  name  or  the  NIS/YP  domain name.  hostname uses the
   sethostname(2) function, while all of the three domainname,  ypdomain‐
   name  and  nisdomainname  use  setdomainname(2).   Note,  that this is
   effective only until the next reboot.  Edit /etc/hostname  for  perma‐
   nent change.

So you have to edit /etc/hostname, not just call hostname yournewhostname.

If your system doesn't have /etc/hostname follow the man page for hostname on your system to resolve which file to change to get the permanent hostname change. Just calling hostname with an argument probably has no permanent effect.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.