Five questions about modifying hostname under Linux (iv)

Source: Internet
Author: User

After a few days of discussion, I believe we have a very deep understanding of how to modify hostname under Linux, then we will talk about the fourth question today.

Question 4: Does the hostname have anything to do with/etc/hosts configuration?

If from the above experiment, actually hostname and/etc/hosts under the configuration is not related. Hostname changes and changes are completely independent of the hosts file. In fact, the hosts file functions quite like DNS, providing IP address to hostname correspondence. The number of early Internet computers is low, and the stand-alone hosts file is sufficient to store all networked computers. But with the development of the Internet, this is far from enough. A distributed DNS system is then present. The DNS server provides a similar IP address to the corresponding domain name. Specifically, man hosts can view relevant information.

The Linux system queries the/etc/hosts file before issuing a domain name resolution request to the DNS server, and if it has a corresponding record, it will use the records inside the hosts. /etc/hosts files usually contain this record

127.0.0.1 localhost.localdomain localhost

The Hosts file format is a row of records, respectively, IP address, hostname, aliases, three are separated by white space characters, aliases optional.

127.0.0.1 to localhost This recommendation does not change because many applications use this, such as SendMail, which may not work properly after the modification.

But, in fact, hostname is not to say with/etc/hosts a little relationship is not. In/etc/rc.d/ Rc.sysinit, the following logic is determined, when the hostname is localhost localhost.localdomain, will use the interface IP address corresponding to the hostname to reset the system hostname.

1234567891011121314151617181920212223 # In theory there should is no more than one network interface active      # this early in T He boot process-the one we ' re booting from.      # use the network address to set the HOS Tname of the client. this      # must be do even if we have local storage.       ipaddr=      if ["$HOSTNAME" = "localhost"-o "$HOSTNAME" = " Localhost.localdomain "]; then              ipaddr=$ (IP addr Show to 0 /0 Scope Global | awk '/[[:space:]]inet/{print gensub ("/.*", "" "," G ", $)} ')                if [-N "$ipaddr"]; then                       eval $ (ipcalc-h $ipaddr 2>/dev/null)                        Hostname ${hostname}              fi       fi

Let's experiment with it, modify the hosts, the network file, and the modified values are as follows:

12345678910 [[email  protected] localhost~]# more/etc/hosts# don't remove the following line, or various programs# that require network Functionality'll fail.::1 Localhost.localdomain localhost127.0.0.1 localhost.localdomain localhost192.168.244.128 Db-server.localdomain db-server[[email protected] localhost  ~]# more/etc/sysconfig/networknetworking= Yesnetworking_ipv6=yeshostname=localhost.localdomain

After rebooting the system, let's look at the situation:

So that's why sometimes people think that the value of hostname is related to the hosts file.

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

Five questions about modifying hostname under Linux (iv)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.