How does the /etc/hosts file take effect after modification?

1. How to take effect after the /etc/hosts file is modified

        After modifying /etc/hosts, it should normally take effect immediately after saving, but sometimes it is not. Use uname -a to see what the hostname is, and then you can know whether the modification takes effect. If not, the strategies at this time are:

1) Restart the machine

2) Restart the service

        Ubuntu: $sudo /etc/init.d/networking restart

        Gentoo: /etc/init.d/net.eth0 restart

3) Use the hostname command

        hostname defined hostname

 

2. The relationship between hostname and /etc/hosts

        When many people mention changing the hostname, they first think of modifying the /etc/hosts file, thinking that the configuration file of the hostname is /etc/hosts. Actually not.

        The role of the hosts file is equivalent to DNS, providing the correspondence between IP addresses and hostnames. The early Internet computers were few, and the hosts file of a single machine was enough to store all networked computers. But with the development of the Internet, this is far from enough. So there is a distributed DNS system. A similar IP address to domain name correspondence is provided by a DNS server. Specifically, you can man hosts.

        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 the hosts will be used. The /etc/hosts file usually contains this record.

 

3. /etc/hosts file description

127.0.0.1    localhost.localdomain   localhost

        The format of the hosts file is one record per line, which are IP address hostname aliases. The three are separated by blank characters, and aliases are optional.

        It is recommended not to modify 127.0.0.1 to localhost, because many applications will use this, such as sendmail, and these programs may not work properly after modification.

 

Article source: http://blog.sina.com.cn/s/blog_605f5b4f0101847z.html

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=327009691&siteId=291194637