Page 1 of 2

Won't take hostname

Posted: 2009/02/24 06:21:10
by DennyCrane
I've searched the Web looking for how to update the hostname on a CentOS machine, and I've found several references to updating /etc/hosts and /etc/sysconfig/network and even creating a file /etc/hostname, as well as setting via hostname and dnsdomainname, but none of those methods seems to be working for me. When I reboot, all of those files go back to the way they were (save the /etc/hostname file, which doesn't seem to have any effect).

Re: Won't take hostname

Posted: 2009/02/24 06:41:17
by RobTheAdmin
I don't think the hosts file is the right place. Instead try editing /etc/sysconfig/network.

Insert "HOSTNAME=blahblahblah" in there.

That should do it.

For more info see: http://www.crucialp.com/blog/2008/02/25/configuring-network-interfaces-on-centos-redhat-fedora-core-and-debian/

Re: Won't take hostname

Posted: 2009/02/24 13:47:48
by AlanBartlett
A [b]man hostname[/b] command will tell you all you need to know.

[b]Rob[/b] is quite correct (if he wasn't, he wouldn't deserve the [i]TheAdmin[/i] epithet :-D ), the [b]/etc/sysconfig/network[/b] file is the place that your [i]hostname[/i] should be defined.

Re: Won't take hostname

Posted: 2009/02/24 13:54:59
by DennyCrane
Yes, I've tried that. The hostname was previously set to subdomain. I've tried entering the new subdomain by itself as well as the subdomain.domain.com, but when I reboot, it goes back to what it was....

:-(

Re: Won't take hostname

Posted: 2009/02/24 14:06:57
by DennyCrane
[quote]
AlanJBartlett wrote:
A [b]man hostname[/b] command will tell you all you need to know.

[b]Rob[/b] is quite correct (if he wasn't, he wouldn't deserve the [i]TheAdmin[/i] epithet :-D ), the [b]/etc/sysconfig/network[/b] file is the place that your [i]hostname[/i] should be defined.[/quote]

Do you have any suggestion as to why it will not work in my case?

Should it make any difference that we are using ISPConfig Control Panel? Actually, I reset the host in ISPConfig, too, and that's the only change that seems to be sticking. I can get to the CP from the new domain, but error pages reference the old host and I can see quite plainly that the machine still thinks it is the old host. I've edited the file, restarted the network and httpd services, rebooted the machine, etc. When I reboot the machine, I lose my changes.

Won't take hostname

Posted: 2009/02/24 14:27:06
by gerald_clark
Although /etc/sysconfig/network is the place to set the host name, it had better agree
with the hostname for your IP in /etc/hosts.

Re: Won't take hostname

Posted: 2009/02/24 15:05:20
by DennyCrane
Perhaps the only way to do this is to show exactly what I'm doing ...

Before changes:

[code]
[root@server ~]# hostname
server
[root@server ~]# dnsdomainname
loneoakcampsites.com
[root@server ~]# hostname vps
[root@server ~]# dnsdomainname pelland.com
dnsdomainname: You can't change the DNS domain name with this command

Unless you are using bind or NIS for host lookups you can change the DNS
domain name (which is part of the FQDN) in the /etc/hosts file.
[root@server ~]# hostname
vps
[/code]


/etc/sysconfig/network (before editing):

[code]NETWORKING="yes"
NETWORKING_IPV6=no
HOSTNAME="server"
GATEWAY="216.235.64.1"[/code]

/etc/sysconfig/network (after editing):

[code]NETWORKING="yes"
NETWORKING_IPV6=no
HOSTNAME="vps"
GATEWAY="216.235.64.1"[/code]

/etc/hosts (before editing):

[code]127.0.0.1 localhost.localdomain localhost
# Auto-generated hostname. Please do not remove this comment.
216.235.66.231 server.loneoakcampsites.com server vz231-66-231 server[/code]

/etc/hosts (after editing):

[code]127.0.0.1 localhost.localdomain localhost
# Auto-generated hostname. Please do not remove this comment.
216.235.66.231 vps.pelland.com vps vz231-66-231 vps[/code]


After editing the above two files:

[code][root@server ~]# hostname
vps
[root@server ~]# dnsdomainname
pelland.com[/code]

Then I restart the network and httpd services:

[code][root@server ~]# service network restart
Shutting down interface eth0: [ OK ]
Shutting down loopback interface: [ OK ]
Bringing up loopback interface: [ OK ]
Bringing up interface eth0: [ OK ]
[root@server ~]# service httpd restart
Stopping httpd: [ OK ]
Starting httpd: [ OK ][/code]

After logging-out and then logging back in (it shows vps at the prompt instead of server):

[code][root@vps ~]# [/code]

After testing the error pages by going to http://vps.pelland.com:81/ ("forgetting" to use http[b]s[/b]) (note the old hostname is referenced in the "hint"):

[code]Bad Request
Your browser sent a request that this server could not understand.
Reason: You're speaking plain HTTP to an SSL-enabled server port.
Instead use the HTTPS scheme to access this URL, please.
Hint: [b]https://server.loneoakcampsites.com:81/[/b][/code]

After rebooting? All the files go back to what they were originally, except that /etc/hosts keeps one little change (in bold):

[code]127.0.0.1 localhost.localdomain localhost
# Auto-generated hostname. Please do not remove this comment.
216.235.66.231 server.loneoakcampsites.com server vz231-66-231 [b]vps[/b][/code]

Am I doing something wrong or missing something? vps.pelland.com is pointed at the 216.235.66.231 IP address in the DNS, but the rest of the domain is on a different server (but the same is true for loneoakcampsites.com (one of our clients' domain)).

Re: Won't take hostname

Posted: 2009/02/24 16:45:41
by gerald_clark
Something is re-writing /etc/hosts.
# Auto-generated hostname. Please do not remove this comment.

What is doing this?
Are you running a virtual machine?
If so, the vmclient startup may be overriding your changes.

Re: Won't take hostname

Posted: 2009/02/24 16:48:27
by DennyCrane
It is a Virtual Private Server, so yeah, it's a virtual machine. Thanks for the suggestion -- I'll take another look around and let you know whether I find anything.

Re: Won't take hostname

Posted: 2009/02/24 17:26:26
by RobTheAdmin
[quote]
AlanJBartlett wrote:
A [b]man hostname[/b] command will tell you all you need to know.

[b]Rob[/b] is quite correct (if he wasn't, he wouldn't deserve the [i]TheAdmin[/i] epithet :-D ), the [b]/etc/sysconfig/network[/b] file is the place that your [i]hostname[/i] should be defined.[/quote]

Haha, well, I wouldn't say I *deserve* TheAdmin epithet. I'm a true Linux newb, yet I am The Admin at my company, which is why I chose this username. Always verify what I say, I could be exceptionally wrong!