When I feel that the Linux system changes hostname already very familiar with the time, encountered a few problems, these questions give me a good lesson, a lot of knowledge points, when you think you have mastered, in fact, you know is only fur. Technical work, do not taste the stop!
Lab environment: Red Hat Enterprise linux Server release 5.7 (Tikanga), other Linux versions may be different. Please take the actual circumstances as the subject.
In fact, I have modified hostname many times, generally only need to modify the/etc/hosts and/etc/sysconfig/network two files under the relevant configuration can be. However, today I have two questions:
Question 1: why/etc/sysconfig/ The hostname in the network configuration file is Localhost.localdomain, but the hostname shown is po132345806-a, where is the configuration value for hostname?
1 |
1: [[email Protected] ~]# more/etc/hosts 2: # don't remove the following line, or various programs 3: # that require network Functi Onality would fail. 4:127.0.0.1 localhost.localdomain localhost 5::: 1 localhost6.localdomain6 localhost6 6: [[email protected] ~]# Mor E/etc/sysconfig/network 7:networking=yes 8:networking_ipv6=yes 9:hostname=localhost.localdomain |
There is a picture of the truth, lest people do not believe this phenomenon, when I first encountered this special situation, I was very puzzled. Google has some information to add its own practice to understand
Issue 2: After modifying the hostname, how to make it effective immediately without restarting the operating system.
3: How many different ways to modify hostname?
Does the problem 4:hostname have anything to do with/etc/hosts configuration?
Question 5: How do I see the value of hostname, whichever is that?
Today, let's talk about the first question first.
Question 1 Answer: I always thought that the value of hostname is configured in/etc/sysconfig/network, this file inside hostname configuration Why, hostname value is what. But why does that happen? Does/etc/sysconfig/network
Not a hostname configuration file, is there another configuration file? So I was experimenting. Modified/etc/sysconfig/network file hostname to Db-server, found
The value of the hostname is still unchanged, so the computer is restarted
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.GF g1.esquel.com 8:132345806-a ~]# 9:132345806-a ~]# reboot |
After reboot found incredibly hostname into db-server, that is, modify the configuration file/etc/sysconfig/network hostname effective. So that means someone has modified the kernel.hostname, see the following experiment
1: [[email protected] ~]# more/etc/sysconfig/network 2: 3:networking=yes 4: 5:networking _ipv6=yes 6: 7:hostname=db-server.localdomain 8: 9: [[email protected] ~]# echo Test >/ PROC/SYS/KERNEL/HOSTNAME 10: 11: [[email protected] ~]# more/etc/proc/sys/kernel/hostname 12:  13:/etc/proc/sys/kernel/hostname:no Such file or directory 14: 15: [[email protected] ~]# more/p ROC/SYS/KERNEL/HOSTNAME 16: 17:test 18: 19: [[email protected] ~]#/etc/init.d/network RESTART 20: 21:shutting 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: [[email protected] ~]# HOSTNAME 34: 35:test 36: &NBsp;37: [[email protected] ~]# 38: |
Note: In fact/etc/init.d/network restart no use. It was only when the experiment thought that the network service had to be restarted.
Create a new clone in SecureCRT a session found that Hostanme has changed from db-server to test, but the value of/etc/sysconfig/network is Db-server.localdomain and has not changed to test.
12345678910111213141516171819202122232425262728 |
[[email protected] Test ~]# more/etc/sysconfig/network 2: 3: networking=yes 4: 5:NETWORKING_IPV6=yes 6: 7:HOSTNAME=DB-Server.localdomain 8: 9: [[email Protected] Test ~]# hostname 10: 11:Test 12: 13: [Email protected] Test ~]# more/etc/hosts 14: 15: # Don't remove the following line, or Vari ous programs 16: 17: # that require network functionality would fail. 18: & nbsp; 19:127.0.0.1 localhost.localdomain localhost 20: 21::: 1 LOCALHOST6.LOCALDOMAIN6 localhost6 22: 23: [[email protected] Test ~]# more/proc/ sys/kernel/hostname 24: 25:Test 26: 27: [[Email protected] Test ~]# 28: |
However, if you restart the system hostname will become db-server,google some English documents to know, hostname is a kernel parameter under the Linux system, it is saved under/proc/sys/kernel/hostname, However, its value is read from Rc.sysinit when Linux is started.
Hostname is a kernel parameter which stores hostname of the system. It is "/proc/sys/kernel/hostname"
The value for this parameter are loaded to kernel by Rc.sysinit file during the boot process.
and hostname in/ETC/RC.D/RC.SYSINIT from hostname under/etc/sysconfig/network, the code is as follows, We can understand it completely.
12345678910111213141516171819 |
hostname= '/bin/hostname ' hosttype= ' uname-m ' unamer= ' uname-r ' set-m if [-f/ Etc/sysconfig/network]; then . /etc/sysconfig/network fi if [-Z] $HOSTNAME "-o" $HOSTNAME "=" (none) "]; Then hostname=localhost fi |
Conclusion:/etc/sysconfig/network is indeed a hostname configuration file, and the value of hostname is associated with the hostname in the configuration file, but there is no certainty that the hostname value comes from the kernel parameter/proc/ Sys/kernel/hostname, if I change the kernel parameters by command Sysctl kernel.hostname=test, then the hostname becomes test.
What to expect, and listen to tell
If you want to dive into the Linux system novice, you can also download a German Linux software center trial.
Free: Http://www.nfs-cloud.cn:81/appCenter/open/softcenter
In-depth discussion on the five issues of modifying hostname under Linux (i)