Home / تنظیم hostname در centos

تنظیم hostname در centos


  1. [root@vps12 ~]# hostname  
  2. vps12  


We can also check via sysctl kernel.hostname

  1. [root@vps12 ~]# sysctl kernel.hostname  
  2. kernel.hostname = vps12  


The actual hostname I need to set for this server is blanche.mydomain.net

I can set the hostname initially using the hostname command followed by the desired hostname.

  1. [root@vps12 ~]# hostname blanche.mydomain.net  


This will set the hostname:

  1. [root@vps12 ~]# hostname  
  2. blanche.mydomain.net  


However, once the server is rebooted, the hostname will revert to it's previous setting (vps12).

To permanently change the hostname, I need to edit the network file at /etc/sysconfig/network.

So,

  1. [root@vps12 ~]# cd /etc/sysconfig  
  2. [root@vps12 sysconfig]# vi network  


The Network file will look as so.

  1. NETWORKING=yes  
  2. HOSTNAME=vps12  
  3. GATEWAYDEV=eth0  
  4. GATEWAY=192.168.0.1  


Hit 'i' to insert and change the HOSTNAME value to your FQDN, in my case, blanche.mydomain.net

Hit Escape, then :wq to save and exit.

Check that the hostname is properly set:

  1. [root@vps12 sysconfig]# hostname  
  2. blanche.mydomain.net  
  3. [root@vps12 sysconfig]# sysctl kernel.hostname  
  4. kernel.hostname = blanche.mydomain.net  


Finally, if we log out, and log back in using a new session, we see I am now root@blanche: 

  1. login as: root  
  2. root@blanche's password:  
  3. Last login: Mon Jun 28 16:21:53 2010  
  4. [root@blanche ~]#    


To properly check, you may wish to reboot the server.



     RSS of this page