/etc/hostname和/etc/hosts区别( 二 )


但是呢,其实也不是说跟/etc/hosts一点关系都没有 。在/etc/rc.d/rc.中,有如下逻辑判断,当为后.时,将会使用接口IP地址对应的来重新设置系统的 。
# Intherebe no more than one
# this early in the boot-- the one we'refrom.
# Use theto set theof the . This
# must be done even if we have local .
=
if [ "$" = "" -o "$" = "." ]; then
=$(ip addr show to 0/0 scope| awk '/[[:space:]]inet / { print ("/.*","","g",$2) }')
if [ -n "$" ]; then
eval $( -h $ 2>/dev/null)
${}

/etc/hostname和/etc/hosts区别

文章插图
fi
fi
我们来实验一下吧,修改hosts、文件,修改后的值如下所示:
[root@localhost ~]# more /etc/hosts
# Do not remove the following line, or various programs
# that require network functionality will fail.
::1 localhost.localdomain localhost
127.0.0.1 localhost.localdomain localhost
192.168.244.128 DB-Server.localdomain DB-Server
[root@localhost~]# more /etc/sysconfig/network
NETWORKING=yes
NETWORKING_IPV6=yes
HOSTNAME=localhost.localdomain
重启系统后,我们再截图看看情况:
/etc/hostname和/etc/hosts区别

文章插图
所以这也是有时候人们以为的值跟hosts文件有关系的缘故 。
问题5:如何查看的值,以那个为准?
[root@DB-Server ~]# hostname
DB-Server
[root@DB-Server ~]# more /proc/sys/kernel/hostname
DB-Server
[root@DB-Server ~]# more /etc/sysconfig/network
NETWORKING=yes
NETWORKING_IPV6=yes
HOSTNAME=localhost.localdomain
以那个为准呢,如果你理解了前面4个问题,那么理解这个问题就很简单了 。