Hosts file details

Source: Internet
Author: User

A file named hosts exists in both Linux and Windows systems. It is a text file and can be edited manually.

The role of the hosts file is simple: speed up domain name resolution. it stores some of the most frequently used domain names and IP ing relationships, or domain names or host addresses that are not commonly used but never change the IP address. for example, if the IP address of cnblogs.com never changes, you can write it to the hosts file. If you need to access cnblogs.com later, you no longer need to perform DNS resolution first, however, you can directly find the IP address in the hosts file and directly access it.

The purpose of the hosts file shows that the hosts file can have other functions. for example, if you want to disable access to www.deniedwebsite.com from a local user, you can map it to an invalid IP address in the hosts file, you can also map it to a secure address, such as the cnblogs.com IP address, or even directly map it to the local ip127.0.0.1. so that when you visit that website in the future, as the system detects that the hosts file already has its ing, the system will not allow DNS to perform address resolution, but directly select the specified IP address in the hosts file for access.

The following describes the hosts file format.

The hosts file is a text file, and each address ing occupies one line. The format of each line is as follows:

IP address host or domain name [host alias] [host alias]...

IP addresses and hosts are required. They can be followed by one or more aliases. Separate different fields with one or more spaces (or tabs.

The hosts file can contain comments. The content after line # is ignored by the system as comments.

Generally, the hosts file must contain at least the following content:

127.0.0.1 localhost. localdomain

It means to map localhost to the local machine.

If you do not have this line of content, the system will "do not know localhost. even Ping localhost won't work. if the application calls the system function gethostbyname ("localhost"), it will get a not_found error. of course. because there is no localhost In the hosts file, the system will let the DNS resolve the localhost. The answer should be: the host does not exist.

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.