"Linux" About IP Direct file hosts

Source: Internet
Author: User

Hosts file often hear, change the hosts what, but the real role of this file? The online interpretation of this document is always a theory that is too long to see. Let me see the dizziness.


First, the basic theory of the hosts

In fact, the hosts file in any system has, this hosts in any system does not have a suffix, is a system equivalent to the global variables of things,

The path to Linux is/etc/hosts, and Android is rooted in/system/etc/hosts,ios in Ifile/etc,windows in C:\windows\system32\drivers\etc\. Among them, Android, iOS includes all kinds of tablets, mobile phones, notebooks, even those cameras, televisions. Like Linux, you can do this by:

sudo gedit/etc/hosts
Or

sudo vim/etc/hosts
Open, after editing can exit, no graphical Linux using vim: q:w instruction can complete the editing:


Windows uses Notepad, and the rest of the system calls the respective text editor with the highest administrator privileges to open the file.

This hosts all the notes that begin with # are useless. Do not start with #, must meet the following format:

IP Address host name alias 1 alias 2: (aliases can not be used)

such as 127.0.0.1 localhost. debugging PHP in Apache, or Tomcat debugging the JSP, entering localhost in the browser is equivalent to accessing the 127.0.0.1 address. The routing packet goes directly to the 127.0.0.1 address without having to be interpreted by DNS. Direct access. The system defaults to this setting and retains its own intranet address.

Here the so-called Alias, is another hostname, such as 127.0.0.1 localhost.localdomain localhost, If you enter Localhost.localdomain or localhost, the system will simply throw the packet to the 127.0.0.1 address.

This is not only the browser's routing packet to such processing, you in this machine all the software, will be such processing, such as MySQL access address, localhost:3306. That is to access the data to 127.0.0.1 's 3306 port.

An IP has 65,536 ports for hanging in different applications under the same IP.

Each machine has a hostname for easy separation between the host and the host.

So what's the use of that?


Second, the application of the hosts

Well, speaking so much, it's time to come up with something practical. Tell everyone how to change the Hosts file.

1, if you want a Web site or application will no longer access the extranet. That is, you can no longer communicate with the external network, you will be in the hosts to make up such a piece:

127.0.0.1 the URL you want to block

This way you enter the URL of the communication packet will always be in the intranet of your PC to play circle, never out. Because of their requests for access, they are always left in 127.0.0.1.

2, if you want to speed up a bit faster, direct communication with certain addresses. Go online and find the address you want to speed up.

You can also ping the URL first.

For example I want to visit www.csdn.net speed up. I ping the IP address of the www.csdn.net is 114.112.73.194.

I want to visit CSDN's blog module quickly, I will ping, found that the Blog.csdn.net IP address is 114.112.73.198.

Then add the following to the hosts:

Then the other modules of the CSDN the same.

After you add the Hosts file, your communication packet goes directly to 114.112.73.194, as shown in the article "Linux" about route tracking Directive traceroute (click to open link), your communication packet will go to all levels of the server, looking for the domain name corresponding IP, if you cannot find , and throw it to the superiors to find it again. Although this process can be completed in 1 seconds. At the same time Guo Jia router is also well-arranged, can quickly help you find the nearest place to parse. Therefore, there are not many individuals, the domestic web site to write to the hosts file.

So, the question comes, "Linux" on the Route Tracking command traceroute (click Open link) as shown in the article, I visit those you understand the site, the communication packet to the provincial level router is refused to parse, using the direct principle of the Hosts file can not? If I find the IP of the websites that you know in some search engines, or just find their hosts configuration ...

Oh, anyway, I tried to be perfectly OK.

"Linux" About IP Direct file hosts

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.