Hosts--the static table lookup for host name (host name query for static tables).
The Hosts file is the last file in the Linux system responsible for fast resolution of IP addresses and domain names, saved in ASCII format under the/etc/directory. The Hosts file contains a mapping between the IP address and the host name, as well as the host alias. In the absence of a domain name resolution server, all network programs on the system query the file to resolve the IP address corresponding to a host name, or you will need to use the DNS service program to resolve it. By adding common domain names and IP address mappings to the Hosts file, you can quickly and easily access them.
Priority: DNS Cache > Hosts > DNS services
Hosts format configuration
The Hosts file can configure host IP with the corresponding host name. On the LAN or the World Wide Web, each host has an IP address, which separates each host and can communicate according to IP. But the IP address does not conform to the memory law of the human brain, so there is a domain name, such as Www.baidu.com. In a local area network, each machine has a host name that is used to differentiate between hosts for easy access.
Hosts file format
IP address host name/domain name (host alias)
The difference between a host name and a domain name is:
Host name is usually used in the LAN, through the Hosts file, the host name is resolved to the corresponding IP.
Domain names are usually used on the Internet, but the priority is lower than the content in the Hosts file, so if you do not want to use the Internet domain name resolution, you can change your Hosts file, add your own domain name resolution.
Hosts file role
A major role is: Offline environment simulation, communication between the two sides in the same LAN want to access the domain name on the Internet, you only need to modify their own/etc/hosts file content.
For example, modify the www.baidu.com IP to 127.0.0.1:
After modifying the/etc/hosts, ping Baidu's effect is shown in the following illustration: