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.
- the ASCII letters
z(in a case-insensitive manner);
- the digits
- 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:
to check FQDN
Changing host name:
Edit host file:
$ vi /etc/host
and add your host info, for example our server ip is 220.127.116.11 and host is host.domain.ctl then, we will add line to the host file like this :
and save /close.
Now edit network file:
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.