How does the/etc/hosts file take effect after modification ?, Etchosts
After modifying/etc/hosts, it is normal that it takes effect immediately after being saved, but sometimes it is not. You can use uname-a to check the hostname and check whether the modification takes effect. If no
The following policies are available:
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
Host Name Defined by hostname
Relationship between hostname and/etc/hosts
Many people mentioned the idea of modifying the hostname first to modify the/etc/hosts file. The configuration file of hostname is/etc/hosts. Actually not.
The hosts file acts like DNS and provides the corresponding IP address to the 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. Man hosts is supported.
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. The/etc/hosts file usually contains this record.
127.0.0.1localhost.localdomainlocalhost
The hosts file is in the format of one record per line, namely, the IP address hostnamealiases. The three are separated by blank characters. aliases is optional.
We recommend that you do not modify the configuration from 127.0.0.1 to localhost, because many applications use this configuration, such as sendmail. After modification, these programs may not run properly.