Fedora 19修改主机名

本文详细介绍了在Fedora19系统中两种修改主机名的方法。一种是临时修改,适用于不需要长期保持的情况;另一种是永久修改,即使系统重启后仍能保留更改。文章还解释了如何通过编辑特定文件来实现这些更改。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值