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

并且在重启后依然生效

转载于:https://www.cnblogs.com/sean-zou/p/3709992.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值