errorCodex - Computer Questions & Solutions Forum


  errorCodex - Computer Questions & Solutions Forum » Blue Screen » Basic How-tos

Basic How-tos Help Us Noobs by Sharing Your Wisdom

Reply
 
Thread Tools
  #1  
Old 22 November 2009, 08:17
Miraenda's Avatar
Miraenda Miraenda is offline
Mime Stalker
 
Join Date: Nov 2009
Location: Coralville Iowa
Age: 37
Posts: 67
Miraenda has disabled reputation
Default Hostname Guide

Existing Hostname

To see the existing hostname on a server, issue the following command:

Code:
hostname
This will return the server's current hostname.
_________________________________

New Hostname


The hostname must be a fully qualified domain name (FQDN) with a DNS zone A record on the server. A subdomain for a domain on the server works best, since many servers will have a conflict in functionality if a domain name with a site on the server is used for the server's hostname. As such, avoid using mydomain.com and pick something like server.mydomain.com for the hostname instead.
_________________________________

STEPS TO CHANGE THE HOSTNAME


The following steps would be taken on systems other than cPanel. Please do not change the A Record, edit Apache, or make changes to the other files noted if using cPanel. The steps for cPanel are detailed at the bottom of this guide.


Creating the A Record Zone

1. At /var/named location, either create a zone file by copying the old hostname zone file, or edit the prior hostname zone file. Change each entry for the old hostname to the new one in the file.

2. Copy /etc/named.conf:

Code:
cp /etc/named.conf /etc/named.conf.bakYYMMDD
Replace YYMMDD with the existing date in 091122 type format where 09 is the year, 11 is the month and 22 is the day of the month.

3. Edit /etc/named.conf and change the prior hostname entry to the new hostname:

Code:
zone "server2.mydomain.com" {
        type master;
        file "/var/named/server2.mydomain.com.db";
};
The server2.mydomain.com entries in lines 1 and 3 should be replaced by the new hostname being used.

Alternatively, a new entry could be placed into /etc/named.conf with the new hostname details without replacing the old hostname entry.

4. Run the command to reload the zone:

Code:
rndc reload server2.mydomain.com
The above command will only reload the zone for this entry. If that command does not work, all zones could be reloaded with just rndc reload.

5. Check the new hostname is resolving for the zone:

Code:
host server2.mydomain.com
The above command should return the IP address you used in the zone file for the new hostname like the following:

Code:
server2.mydomain.com has address IP#
_________________________________

Adding the Hostname to Apache

1. Copy the Apache configuration file, which is normally at either /usr/local/apache/conf/httpd.conf or /etc/httpd/conf/httpd.conf (oftentimes, the file exists at both locations).

Code:
cp /etc/httpd/conf/httpd.conf /etc/httpd/conf/httpd.conf.bakYYMMDD
Replace YYMMDD with the existing date in 091122 type format where 09 is the year, 11 is the month and 22 is the day of the month.

2. Edit httpd.conf file using vi with the find and replace command:

Code:
Esc key, then :%s/oldhostname/newhostname/ and then Enter key
This command will replace the old hostname with the new one for all locations in the file. After replacing the hostname, then save the file using Esc key, then :wq (write quit).

3. Restart Apache:

Code:
/etc/init.d/httpd restart
The restart will ensure the changes to the Apache configuration file reload.
_________________________________

Changing Hostname on Most Systems

The first file needing edited would be /etc/hosts file, which would look similar to this:

Code:
IP          server.mydomain.com server
127.0.0.1   localhost
Here IP will be the server's frontend, public IP. To change the hostname, change the server.mydomain.com and server entries to the new hostname.

After editing and saving that file, then different systems have additional files to edit and/or commands to run in order to process the change.
_________________________________

Individual Systems

Debian

1. Edit /etc/hostname file and put only the new hostname in that file (so it would contain only server.mydomain.com if that is the new hostname).

2. Run the command:

Code:
/bin/hostname -F /etc/hostname
or
Code:
/etc/init.d/hostname.sh start
This command will change the hostname for next login without a reboot being required.

FreeBSD

1. First issue the command:

Code:
hostname newname
For example, if the new hostname would be server2.mydomain.com, then the command would be:

Code:
hostname server2.mydomain.com
The above command will cause the hostname to change to the new one on next server login. This command only changes the hostname until the server reboots. After rebooting, the hostname would switch back to the old one unless Step 2 has been completed.

2. Edit /etc/rc.conf file for the following line:

Code:
hostname="newname"
Again, the newname portion would be the full name being used for the new hostname. The above file change will ensure the hostname will be set on reboot. If this step is processed but Step 1 is not processed, then the hostname will only change on server reboot. The new hostname will not be set on next login by editing this file.

RedHat / CentOS


1. First issue the command:

Code:
hostname newname
For example, if your new hostname would be server2.mydomain.com, then the command would be:

Code:
hostname server2.mydomain.com
The above command will cause the hostname to change to the new one on next server login. This command only changes the hostname until the server reboots. After rebooting, the hostname would switch back to the old one unless Step 2 has been completed.

2. Edit /etc/sysconfig/network file for the following line:

Code:
HOSTNAME=newname
Again, the newname portion would be the full name being used for the new hostname. The above file change will ensure the hostname will be set on reboot. If this step is processed but Step 1 is not processed, then the hostname will only change on server reboot. The new hostname will not be set on next login by editing this file.

cPanel

cPanel servers, regardless of the operating system type, would not have any changes made to /etc/hosts or other files. Instead, use the following steps:

1. Log into WHM.

2. Click on Change Hostname and set the new hostname here.

3. Click on "Add An A Entry for your hostname" button.

cPanel will change the hostname in Basic cPanel/WHM Setup in WHM, in httpd.conf file, in /etc/hosts file, and in any additional file where the hostname is set (such as /etc/sysconfig/network file on RedHat/CentOS). You will also want to update the SSL certificates for the server services in WHM's Manage Service SSL Certificates area by clicking on "Reset Certificate" link for each.

Please note that the /etc/hosts file will simply have the new hostname added into it. The old hostname entries will still be listed as possible names for the server, so the file might end up looking like the following:

Code:
IP          oldhostname.mydomain.com newhostname.mydomain.com newhostname 
oldhostname
127.0.0.1   localhost
Here the old hostname is both oldhostname.mydomain.com and oldhostname and the new hostname is newhostname.mydomain.com and newhostname. These old hostname entries could remain in the /etc/hosts file, since the entries simply allow the server to continue to locally recognize the old hostname for that IP.
Reply With Quote
Reply

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -6. The time now is 19:49.


A vBSkinworks Design
Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.