host file

I recently learned the basics of network security and made a record.

Wikipedia explanation

The Hosts file is an operating system file without an extension, which stores the mapping relationship between host names and IP addresses in the form of a table. Hosts is also called host table, translated as "host table".

In modern systems, although DNS has replaced the host table, the application of the host table is still very wide. Unlike DNS, users can directly control the Hosts file.

The Host file is essentially a small DNS system

To put it in a simple way: DNS is the telephone yellow pages of the whole city, and HOSTS is your personal address book.

When resolving the URL, we will search in the local host file according to the domain name. If we find the corresponding record, we will resolve it to the corresponding ip, otherwise we will make a request to the upper-level DNS system. Repeat this until you find it.

DNS and HOSTS comparison?

The same point: all URLs are resolved into IP addresses

The HOSTS file is equivalent to a small local DNS server. The computer will first search for the corresponding IP in the local HOSTS file. If it is not found, it will request to the higher-level DNS, and if it still does not, it will request it step by step.

application

use

All the uses are actually based on modifying the host to resolve the domain name to different ip addresses, so please use your imagination. A few common usages are given below.

  1. block sites

    Many times, there are some weird websites that you don’t want to visit, so you can specify them in the host file and bind them to your own specified address, such as resolving www.baidu.com to the address of Bilibili (ಥ _ ಥ)

    1. ​ Take a look at an address of station bping bilibili.com
    2. Modify the host file to add at the endimage-20221128154513970
    3. Ping Baidu again and you can see that it has been modified to an ip address of station b
    4. Of course, if you use some browsers to open it, you can’t jump to station b, because this is a very obvious security hole, and the browser and server will perform corresponding detection. It is rare that the domain name and ip do not match. of.
  2. 1. Github520+SwitchHosts (after long-term practice, it is not easy to use)

  3. Speed ​​up domain name resolution (of course, it is not necessary) For frequently visited websites, we can improve the domain name resolution speed by configuring the mapping relationship between domain name and IP in Hosts. Due to the mapping relationship, when we enter the domain name, the computer can quickly resolve the IP without requesting the DNS server on the network.

  4. LAN configuration

    As we said before, it is actually a small DNS system, so we can name our own IP in the local area network for easy memory

set up

computer

In XP, win7, and win10 systems, the HOST file is located in the system C:\Windows\System32\drivers\etcdisk . If you do not see the Hos file, it is because some systems hide the Host file. Note: host is a read-only file, if you need to modify it, please turn off read-only.

cell phone

  • Android system: root directory /system/etc/hosts (use re or es file browser to modify after rooting)

Special thanks to

What is the relationship between web address (url), domain name, ip address, dns, and hosts ? How to set up the hosts file?

Guess you like

Origin blog.csdn.net/qq_40790680/article/details/128971673