What is the difference between hostname and/etc/hosts?

Source: Internet
Author: User


The difference between hostname and/etc/hosts many people mentioned that changing the hostname first comes up with the idea of modifying the/etc/hosts file. The hostname configuration file is/etc/hosts. Actually not. The hosts file acts as DNS and provides the corresponding IP address hostname. There were few computers on the Internet in the early days, and the hosts file on a single machine was enough to store all the computers on the Internet. However, with the development of the Internet, this is far from enough. As a result, a distributed DNS system emerged. The DNS server provides a similar IP address to the corresponding domain name. The Linux system will query the/etc/hosts file before sending a domain name resolution request to the DNS server. If there is a corresponding record in it, the record in hosts will be used. Therefore, setting the hostname in/etc/hosts is not directly related. The/etc/hosts file is used only when you need to map your own IP address with the new hostname on the local machine. There is no bound relationship between the two. The configuration file of the redhat hostname is/etc/sysconfig/network. the following is an excerpt from www.2cto.com/etc/hosts: # Do not remove the following line, or various programs # that require network functionality will fail. 192.168.1.102 localhost. localdomain localhost 127.0.0.1 localhost. localdomain localhost: 1 localhost6.localdomain6 localhost6
Description of the above content: the hosts file is used to map host names to IP addresses. This method is relatively simple. However, this ing is only a local ing. That is to say, each machine is independent and all computers cannot access each other through hostname. Format: www.2cto.com in general, the hosts content defines the Host Name (hostname). Each behavior is a host, each line consists of three parts, each part is separated by a space. The line starting with # is not explained by the system. Part 1: network IP address; Part 2: Host Name. domain name. Note that there is a halfwidth between the host name and domain name, such as localhost. localdomain Part 2: Host Name (host name alias), which is actually the host name; Note: 1) 127.0.0.1 is the back-to-loop address. For example, we do not want other machines on the LAN to see the network program we tested, you can use the loop address for testing. 2) Why do I need to define a domain name? In fact, it is easy to understand. For example, we have three hosts, each of which does different things. One is a MAIL server, the other is an FTP server, and the other is an SMB server, so we can design hostname; www.2cto.com 127.0.0.1 localhost. localdomain localhost 192.168.1.2 ftp 192.168.1.3 mail. localdomain mail 192.168.1.4 smb. localdomin smb writes the content of the preceding configuration file to the/etc/hosts content of each machine separately, so that the machines on the three LAN can access the file through hostname. That is, in the LAN, the host name can also be resolved to the IP address, which is equivalent to DNS domain name resolution. You can modify the host name in either of the following ways: hostname and/etc/sysconfig/network [SQL] [root @ think ~]. # Hostname thin www.2cto.com [root @ think ~] # Hostname think [root @ think ~] # Hostname think uses the hostname kernel variable to set the host name to be temporary. When the system is restarted next time, the host name will not exist. hostname can also be used to display: hostname-I. If you want to permanently modify the RedHat hostname, modify the/etc/sysconfig/network file and change the HOSTNAME line to HOSTNAME = NEWNAME. NEWNAME is the hostname you want to set.
 

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.