Won't take hostname

Issues related to configuring your network
DennyCrane
Posts: 33
Joined: 2009/02/18 14:02:50

Won't take hostname

Postby DennyCrane » 2009/02/24 06:21:10

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).

RobTheAdmin
Posts: 80
Joined: 2008/03/30 13:58:12
Location: Tennessee
Contact:

Re: Won't take hostname

Postby RobTheAdmin » 2009/02/24 06:41:17

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 ... nd-debian/

User avatar
AlanBartlett
Forum Moderator
Posts: 9311
Joined: 2007/10/22 11:30:09
Location: ~/Earth/UK/England/Suffolk
Contact:

Re: Won't take hostname

Postby AlanBartlett » 2009/02/24 13:47:48

A man hostname command will tell you all you need to know.

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

DennyCrane
Posts: 33
Joined: 2009/02/18 14:02:50

Re: Won't take hostname

Postby DennyCrane » 2009/02/24 13:54:59

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....

:-(

DennyCrane
Posts: 33
Joined: 2009/02/18 14:02:50

Re: Won't take hostname

Postby DennyCrane » 2009/02/24 14:06:57

AlanJBartlett wrote:
A man hostname command will tell you all you need to know.

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


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.

gerald_clark
Posts: 10642
Joined: 2005/08/05 15:19:54
Location: Northern Illinois, USA

Won't take hostname

Postby gerald_clark » 2009/02/24 14:27:06

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.

DennyCrane
Posts: 33
Joined: 2009/02/18 14:02:50

Re: Won't take hostname

Postby DennyCrane » 2009/02/24 15:05:20

Perhaps the only way to do this is to show exactly what I'm doing ...

Before changes:

Code: Select all

[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



/etc/sysconfig/network (before editing):

Code: Select all

NETWORKING="yes"
NETWORKING_IPV6=no
HOSTNAME="server"
GATEWAY="216.235.64.1"


/etc/sysconfig/network (after editing):

Code: Select all

NETWORKING="yes"
NETWORKING_IPV6=no
HOSTNAME="vps"
GATEWAY="216.235.64.1"


/etc/hosts (before editing):

Code: Select all

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


/etc/hosts (after editing):

Code: Select all

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



After editing the above two files:

Code: Select all

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


Then I restart the network and httpd services:

Code: Select all

[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  ]


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

Code: Select all

[root@vps ~]#


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

Code: Select all

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]


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

Code: Select all

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]


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)).

gerald_clark
Posts: 10642
Joined: 2005/08/05 15:19:54
Location: Northern Illinois, USA

Re: Won't take hostname

Postby gerald_clark » 2009/02/24 16:45:41

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.

DennyCrane
Posts: 33
Joined: 2009/02/18 14:02:50

Re: Won't take hostname

Postby DennyCrane » 2009/02/24 16:48:27

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.

RobTheAdmin
Posts: 80
Joined: 2008/03/30 13:58:12
Location: Tennessee
Contact:

Re: Won't take hostname

Postby RobTheAdmin » 2009/02/24 17:26:26

AlanJBartlett wrote:
A man hostname command will tell you all you need to know.

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


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!