Knowledgebase: VPS Tutorials
Change Hostname of Linux, CentOS, Ubuntu and Debian
Posted by RAJU K, Last modified by RAJU K on 25 January 2016 02:14 AM

Changing the Hostname

You’ll need to set your system’s hostname and fully qualified domain name (FQDN). Your hostname should be something unique. Note that the system’s hostname has no relationship to websites or email services hosted on it, aside from providing a name for the system itself. Your hostname should not be “www” or anything too generic.

Hostname's examples, "server1", "wwwbox2", or "server50.mydomain.com".

 

CentOS 7 / Debian 8 / Fedora version 18 and above / Ubuntu 15.04

Replace hostname with one of your choice.

hostnamectl set-hostname hostname

 

Debian 7 / Slackware / Ubuntu 14.04

Replace hostname with one of your choice.

 

echo "hostname" > /etc/hostname 

hostname -F /etc/hostname

 

Check if the file /etc/default/dhcpcd exists.

ls /etc/default
 

If so, edit it and comment out the SET_HOSTNAME directive:

/etc/default/dhcpcd
#SET_HOSTNAME='yes'

 

CentOS 6 / Fedora version 17 and below

Replace hostname with one of your choice.

1) echo "HOSTNAME=hostname" >> /etc/sysconfig/network
2) hostname "hostname"

 

Update /etc/hosts

Next, edit your /etc/hosts file to resemble the following example, replacing hostname with your chosen hostname, example.com with your system’s domain name, and 67.227.230.55 with your system’s IP address. As with the hostname, the domain name part of your FQDN does not necessarily need to have any relationship to websites or other services hosted on the server (although it may if you wish). As an example, you might host “www.something.com” on your server, but the system’s FQDN might be “mars.somethingelse.com.”

/etc/hosts
127.0.0.1 localhost.localdomain localhost 
67.227.230.55 hostname.example.com hostname
 

If you have IPv6 enabled on your Linode, you will also want to add an entry for your IPv6 address, as shown in this example:

/etc/hosts
127.0.0.1 localhost.localdomain localhost 
67.227.230.55 hostname.example.com hostname 
0:0:0:0:0:ffff:43e3:e637 hostname.example.com hostname

 

Now your VPS is ready with new hostname.

 


Comments (0)
Post a new comment
 
 
Full Name:
Email:
Comments:
CAPTCHA Verification 
 
Please enter the text you see in the image into the textbox below (we use this to prevent automated submissions).