CentOS 7.0 修改hostname

浏览次数:2178 关键词 ( CentOS  hostname  )

centos中修改hostname,可以临时修改hostname也可以永久修改,临时修改无需重新启动,立即生效。

临时修改hostname
#hostname //查看当前hostname 
#hostname newname  //临时修改hostname
永久修改hostname

要永久修改hostname需要修改文件,man hostname查看使用手册是,有这样一段,

SET NAME  When called with one argument or with the - -file option, the commands  set the host name or the NIS/YP domain name. hostname uses the  sethostname(2) function, while all of the three domainname, ypdomain‐name and nisdomainname use setdomainname(2). Note, that this is effec‐  tive only until the next reboot. Edit /etc/hostname for permanent  change.

如果我们要修改永久修改hostname,可以通过修改/etc/hostname 文件来实现,使用vim将该文件中的hostname 替换为要修改的值即可。


注:  如果要永久修改RedHat的hostname,就修改/etc/sysconfig/network文件,将里面的HOSTNAME这一行修改成HOSTNAME=NEWNAME,其中NEWNAME就是你要设置的hostname。