How to change hostname in centos ?

How to change Hostname centos?

Changing hostname is fairly easy task . Hostname must be unique so usually its look like sudomain in a fully qualified domain name like host.mydomain.ctl. Providing fully qualified domain name will help server to reach to other network due to its uniqueness. So for the server which is connected to internet, its prefered as domain name as it will be unique in world wide network.

 

Naming convention:

  • the ASCII letters a through z (in a case-insensitive manner);
  • the digits 0 through 9; and
  • the hyphen (-).

No other symbols, punctuation characters, or white space are permitted.

 

Checking Hostname & FQDN

Current hostname can be viewed in current server by follow commands:

$ hostname

to check FQDN

$ dnsdomainname

 

Changing host name:

Edit host file:

$ vi /etc/host

and add your host info, for example our server ip is 66.99.0.1 and host is host.domain.ctl then, we will add line to the host file like this :

66.99.0.1 host.domain.ctl

and save /close.

Now edit network file:

vi /etc/sysconfig/network

and add:

HOSTNAME = host.domain.ctl

 

Now restart network services:

 

$ service network restart

 

Setting Hostname  from command line:

We can also set hostname from command line but this will be lost once the server is restarted.

$ hostname host.domain.ctl

finally, verify the hostname by typing hostname and you will see your new hostname.

$ hostname

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s