Detailed Linux system under the Hosts file

Source: Internet
Author: User

Hosts file

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:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.