首页 >> 知识 >> 修改centos的hostname

修改centos的hostname

步骤

uname -a (或者hostname)可以看到hostname,修改步骤如下:

uname -a 查看hostnamehostname newname 修改下,让hostname立刻生效。vi /etc/hosts 修改原hostname为 newnamevi /etc/sysconfig/network 修改原hostname为 newname , reboot重启后也生效

reboot重启,uname -a 重新检查下。Done!

解析临时生效

Linux操作系统的 hostname是一个kernel变量,可以通过hostname命令来查看本机的hostname。

[root@entel2 ~]# hostnameentel2

也可以直接cat /proc/sys/kernel/hostname查看。

[root@entel2 ~]# cat /proc/sys/kernel/hostnameentel2#hostname#cat /proc/sys/kernel/hostname

上面两种输出结果相同。

修改运行时Linux系统的hostname,即不需要重启系统  hostname命令可以设置系统的hostname

#hostname newname

newname即要设置的新的hostname,运行后立即生效,但是在系统重启后会丢失所做的修改,如果要永久更改系统的hostname,就要修改相关的设置文件。

永久更改Linux的hostname

man hostname里有这么一句话,

The host name is usually set once at system startup in  /etc/rc.d/rc.inet1 or /etc/init.d/boot (normally by reading the  contents of a file which contains the host name, e.g. /etc/hostname).”

RedHat里没有这个文件,而是由/etc/rc.d/rc.sysinit这个脚本负责设置系统的hostname,它读取/etc/sysconfig/network这个文

网站地图