Fedora 19修改主机名

Distribution为Fedora 19

方式一(重启后失效,需root权限)

hostname 新主机名
[root@promote hadoop]# hostname
promote.cache-dns.local
[root@promote hadoop]# hostname fedora
[root@promote hadoop]# hostname
fedora

方式二(重启后依然生效,需root权限)

网上有很多人说只要修改/etc/sysconfig/network文件,在文件中添加如下2行即可:

[root@promote sysconfig]# cat /etc/sysconfig/network
NETWORKING=yes
HOSTNAME=fedora
[root@promote sysconfig]# hostname
promote.cache-dns.local

我实际操作了一次,这种修改方式在Fedora 19中是没有效果的,先使用man hostname看看命令说明,其中有一段很关键

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, ypdomainname and nisdomainname use 
setdomainname(2).Note,that this is effective only until the next reboot.
Edit /etc/hostname for permanent change.

Note,that only the super-user can change the names.

It is not possible to set the FQDN or the DNS domain name with the dnsdomainname 
command(see THE FQDN below).

The host name is usually set once at system startup (normally by reading the 
contents of a file which contains the host name, e.g. /etc/hostname).

这下全明白了,Fedora 9中hostname命令根本不会读取/etc/sysconfig/network文件,它读取的是/etc/hostname文件

将/etc/hostname文件中的内容修改为fedora,没重启就生效了

[root@promote sysconfig]# cat /etc/hostname
fedora
[root@promote sysconfig]# hostname
fedora

并且在重启后依然生效

posted @ 2014-03-04 22:03  心意合一  阅读(310)  评论(0编辑  收藏  举报