Modify/etc/hosts in Linux and etchosts in linux
Directory structure
- Directory structure
- Hosts file
- Hosts format Configuration
- Hosts file Function
Hosts file
Hosts -- the static table lookup for host name (host name query static table ).
The hosts file is a file on Linux that is responsible for fast resolution of IP addresses and domain names. It is saved in the/etc/directory in ascii format. The hosts file contains the ing between the IP address and the host name, as well as the host alias. Without a domain name resolution server, all network programs on the system query the file to resolve the IP address corresponding to a host name. Otherwise, the dns service program is required. You can map common domain names and IP addresses to the hosts file for quick and convenient access.
Priority: dns Cache> hosts> dns Service
Hosts format Configuration
You can configure the Host ip address and the corresponding host name in the hosts file. On a LAN or the World Wide Web, each host has an ip address that separates each host and can communicate with each other based on its ip address. However, IP addresses do not conform to the memory of the human brain, so domain names appear. For example, www.baidu.com. In a LAN, each machine has a host name, which is used to distinguish hosts for mutual access.
Hosts file format
IP address host name/domain name (host alias)
The difference between host name and domain name is that:
- The host name is usually used in the LAN. Through the hosts file, the host name is resolved to the corresponding ip address.
- Domain names are generally used on the internet, but the priority is lower than the content in the hosts file. Therefore, if you do not want to use domain name resolution on the internet, you can change your hosts file and add your own domain name resolution.
Hosts file Function
One of the main functions is to simulate the offline environment. To access each other through the domain names on the internet in the same LAN, you only need to modify the content of your/etc/hosts file.
For example, modify the ip address of www.baidu.com to 127.0.0.1:
After modifying/etc/hosts, ping Baidu as shown in: