centos设置fqdn(全称域名)和hostname的方法【威尼斯
复制代码 代码如下:
要设置一个指定的变量,直接用 variable=value 这样的语法:
编辑 /etc/hosts,增加一行
注意当前会话还是不会变化,但是后续新建会话则会生效。
# cat /etc/sysconfig/network
NETWORKING=yes
HOSTNAME=rdo
[root@DB-Server ~]# more /etc/sysconfig/network
[root@rdo ~]# hostname
rdo
[root@rdo ~]# hostname -f
rdo.test.com
The value for this
parameter is loaded to kernel by rc.sysinit
file during the boot
process.
编辑 /etc/sysconfig/network ,你需要加入一行,记住HOSTNAME,必须大写。
# Use the network address to set the hostname of the client. This
192.168.178.2 rdo.test.com rdo
复制代码 代码如下:
192.168.244.128 DB-Server.localdomain DB-Server
复制代码 代码如下:
1: [root@po132345806-a ~]# more /etc/hosts 2: # Do not remove the following line, or various programs 3: # that require network functionality will fail. 4: 127.0.0.1 localhost.localdomain localhost 5: ::1 localhost6.localdomain6 localhost6 6: [root@po132345806-a ~]# more /etc/sysconfig/network 7: NETWORKING=yes 8: NETWORKING_IPV6=yes 9: HOSTNAME=localhost.localdomain
退出ssh,再登陆,就应该生效。
方法2:修改了/etc/sysconfig/network下的HOSTNAME后,然后使用sysctl kernel.hostname命令使其立即生效
要实现这个效果,需要修改两个文件
127.0.0.1到localhost这一条建议不要修改,因为很多应用程序会用到这个,比如sendmail,修改之后这些程序可能就无法正常运行。
您可能感兴趣的文章:
http://jblevins.org/log/hostname
威尼斯wns.9778官网活动,查看
eval $(ipcalc -h $ipaddr 2>/dev/null)
# Do not remove the following line, or various programs
以那个为准呢,如果你理解了前面4个问题,那么理解这个问题就很简单了。
# must be done even if we have local storage.
实验环境:Red Hat Enterprise Linux Server release 5.7 (Tikanga) ,其它版本Linux可能有所不同。请以实际环境为准。
[root@DB-Server ~]# sysctl kernel.hostname=Test2
在SecureCRT新建克隆一个会话发现hostanme已经从DB-Server变为Test了,但是/etc/sysconfig/network的值还是DB-Server.localdomain,并没有变为Test。
hostname
is a kernel parameter which stores
hostname of the system. Its location
is"/proc/sys/kernel/hostname"
1: "/etc/sysconfig/network" 3L, 66C written
2: 132345806-a ~]# hostname
3: 806-a.gfg1.esquel.com
4: 132345806-a ~]# more /proc/sys/kernel/hostname
5: 806-a.gfg1.esquel.com
6: 132345806-a ~]# sysctl kernel.hostname
7: ostname = po132345806-a.gfg1.esquel.com
8: 132345806-a ~]#
9: 132345806-a ~]# reboot
问题2: 修改了hostname后,如何使其立即生效而不用重启操作系统。
fi
4: 修改/etc/sysconfig/network下的HOSTNAME变量 --需要重启生效,永久性修改。
问题1解答:我一直以为hostname的值配置在/etc/sysconfig/network中,这个文件里面HOSTNAME配置为啥,hostname值就是啥。但是为什么出现上面那种情况呢?难道/etc/sysconfig/network
3: sysctl kernel.hostname=DB-Server --运行后立即生效(新会话生效),但是在系统重启后会丢失所做的修改
当我觉得对Linux系统下修改hostname已经非常熟悉的时候,今天碰到了几个个问题,这几个问题给我好好上了一课,很多知识点,当你觉得你已经掌握的时候,其实你了解的还只是皮毛。技术活,切勿浅尝则止!
[root@localhost ~]# more /etc/hosts
读一个指定的变量,例如 kernel.msgmnb:
[xt@butbueatiful ~]$ sysctl kernel.msgmnb
kern.maxproc: 65536
HOSTNAME=localhost.localdomain
结论:/etc/sysconfig/network 确实是hostname的配置文件,hostname的值跟该配置文件中的HOSTNAME有一定的关联关系,但是没有必然关系,hostname的值来自内核参数/proc/sys/kernel/hostname,如果我通过命令sysctl kernel.hostname=Test修改了内核参数,那么hostname就变为了Test了。
不是hostname的配置文件,难道还另有其它配置文件?于是我当时实验了一下修改了/etc/sysconfig/network文件中HOSTNAME为DB-Server,发现
注意:其实 /etc/init.d/network restart 没有什么用。只是当时实验时以为必须重启网络服务。
https://www.kernel.org/doc/Documentation/sysctl/kernel.txt
方法1:修改了/etc/sysconfig/network下的HOSTNAME后,然后使用echo servername > /proc/sys/kernel/hostname。
但是呢,其实hostname也不是说跟/etc/hosts一点关系都没有。在/etc/rc.d/rc.sysinit中,有如下逻辑判断,当hostname为localhost后localhost.localdomain时,将会使用接口IP地址对应的hostname来重新设置系统的hostname。
1: [root@DB-Server ~]# more /etc/sysconfig/network
2:
3: NETWORKING=yes
4:
5: NETWORKING_IPV6=yes
6:
7: HOSTNAME=DB-Server.localdomain
8:
9: [root@DB-Server ~]# echo Test > /proc/sys/kernel/hostname
10:
11: [root@DB-Server ~]# more /etc/proc/sys/kernel/hostname
12:
13: /etc/proc/sys/kernel/hostname: No such file or directory
14:
15: [root@DB-Server ~]# more /proc/sys/kernel/hostname
16:
17: Test
18:
19: [root@DB-Server ~]# /etc/init.d/network restart
20:
21: Shutting down interface eth0: [ OK ]
22:
23: Shutting down loopback interface: [ OK ]
24:
25: Bringing up loopback interface: [ OK ]
26:
27: Bringing up interface eth0:
28:
29: Determining IP information for eth0... done.
30:
31: [ OK ]
32:
33: [root@DB-Server ~]# hostname
34:
35: Test
36:
37: [root@DB-Server ~]#
38:
fi
[root@Test ~]# hostname DB-Server
HOSTTYPE=`uname -m`
# this early in the boot process -- the one we're booting from.
问题4: hostname跟/etc/hosts 下配置有关系吗?
1: hostname DB-Server --运行后立即生效(新会话生效),但是在系统重启后会丢失所做的修改
# that require network functionality will fail.
[root@DB-Server ~]# echo Test >/proc/sys/kernel/hostname
ipaddr=
# In theory there should be no more than one network interface active
::1 localhost.localdomain localhost
http://www.cnblogs.com/kerrycode/p/3595724.html
NETWORKING_IPV6=yes
**查看所有可读变量:
[xt@butbueatiful ~] sysctl -a
HOSTNAME=`/bin/hostname`
kernel.hostname = Test2
问题5: 如何查看hostname的值,以那个为准?
if [ -f /etc/sysconfig/network ]; then
本文由威尼斯wns.9778官网活动发布于计算机教程,转载请注明出处:centos设置fqdn(全称域名)和hostname的方法【威尼斯
关键词: