fedora修改hostname

来源:互联网 发布:免费看书软件哪个好 编辑:程序博客网 时间:2024/05/01 00:32

Linux Distribution:Fedora 19

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

[plain] view plain copy
print?
  1. hostname 新主机名  
[plain] view plain copy
print?
  1. [root@promote hadoop]# hostname  
  2. promote.cache-dns.local  
  3. [root@promote hadoop]# hostname fedora  
  4. [root@promote hadoop]# hostname  
  5. fedora  

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

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

[plain] view plain copy
print?
  1. [root@promote sysconfig]# cat /etc/sysconfig/network  
  2. NETWORKING=yes  
  3. HOSTNAME=fedora  
  4. [root@promote sysconfig]# hostname  
  5. promote.cache-dns.local  

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

[plain] view plain copy
print?
  1. When called with one argument or with the --file option, the commands set the   
  2. host name or the NIS/YP domain name.hostname uses the sethostname(2) function,   
  3. while all of the three domainname, ypdomainname and nisdomainname use   
  4. setdomainname(2).Note,that this is effective only until the next reboot.  
  5. Edit /etc/hostname for permanent change.  
  6.   
  7. Note,that only the super-user can change the names.  
  8.   
  9. It is not possible to set the FQDN or the DNS domain name with the dnsdomainname   
  10. command(see THE FQDN below).  
  11.   
  12. The host name is usually set once at system startup (normally by reading the   
  13. contents of a file which contains the host name, e.g. /etc/hostname).  

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

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

[plain] view plain copy
print?
  1. [root@promote sysconfig]# cat /etc/hostname  
  2. fedora  
  3. [root@promote sysconfig]# hostname  
  4. fedora  

并且在重启后依然生效

原创粉丝点击