Directory structure
- Directory structure
- Hosts file
- Hosts format configuration
- Hosts file role
Hosts file
Hosts--the static table lookup for host name (host name query for still tables).
The Hosts file is a file that is responsible for fast resolution of IP addresses and domain names in the Linux system, and is stored in the/etc/directory in ASCII format. The Hosts file contains a mapping between the IP address and the host name, and also includes the host alias. In the absence of a domain name resolution server, all network programs on the system can query the file to resolve the IP address corresponding to a host name, otherwise it will need to be resolved by using a DNS service program. Fast and easy access can be achieved by adding common domain names and IP address mappings to the Hosts file.
Priority: DNS Cache > Hosts > DNS service
Hosts format configuration
The Hosts file can be configured with the host IP and the corresponding host name. On a local area network or on the World Wide Web, each host has an IP address that separates each host and can communicate according to the IP. But the IP address does not accord with the human brain's memory law, therefore has appeared the domain name, for example Www.baidu.com. In a local area network, each machine has a hostname, which is used to differentiate the host and facilitate mutual access.
Hosts file format
ip地址 主机名/域名 (主机别名)
the difference between host name and domain name is :
- The hostname is usually used within the LAN, and the host name is resolved to the corresponding IP through the hosts file.
- The domain name is usually used on the Internet, but the priority is lower than the content in the Hosts file, so if you don't want to use domain name resolution on the Internet, you can change your hosts file to include your own domain name resolution.
Hosts file role
One of the main functions is: Offline environment simulation, communication between the two sides in the same LAN want to access through the Internet domain name, then only need to modify their own/etc/hosts file content.
For example, modify the IP of www.baidu.com to 127.0.0.1:
After modifying/etc/hosts, the effect of ping Baidu is as follows:
Linux Modify/etc/hosts