hosts domain name configuration

The URL domain name and its corresponding IP address establish an association "database"
such as: www.baidu.com 1.2.3.4 //Assuming it is 1.2.3.4

Why is there a domain name?

IP address is not easy to remember, so there is a domain name

1. windows under hosts

Hosts is a system file without extension, which can be opened with tools such as Notepad

1.1 The role of hosts

Its function is to establish an association "database" between some commonly used URL domain names and their corresponding IP addresses

  1. Speeding up domain name resolution
    For websites that are frequently visited, we can increase the speed of domain name resolution by configuring the mapping relationship between domain names and IP in Hosts.
    Because of the mapping relationship, when we enter the domain name, the computer can quickly resolve the IP without requesting the DNS server on the network.

  2. Convenient for LAN users
    In many organizations' LANs, there are servers for users to use. However, since DNS servers are rarely set up in the local area network, when accessing these servers, it is necessary to enter an IP address that is difficult to remember.
    This is quite troublesome for many people. You can give these servers an easy-to-remember name, and then set up IP mapping in Hosts, so that when you visit later, you only need to enter the name of the server.

  3. Blocking websites (domain name redirection)
    There are many websites that install various plug-ins on your computer without the user's consent. Some of them may be Trojan horses or viruses. For these websites, we can use Hosts to map the domain name of the website to the wrong IP or the IP of the local computer, so that there is no need to visit. In the WINDOWS system, it is agreed that 127.0.0.1 is the IP address of the local computer and 0.0.0.0 is the wrong IP address.

1.2 The principle of hosts

When the user enters a web address that needs to log in in the browser, the system will first automatically find the corresponding IP address from the Hosts file.
Once found, the system will open the corresponding web page immediately, if not found, the system will submit the web address to DNS again The domain name resolution server performs IP address resolution.

1.3 hosts history

Before the introduction of DNS (Domain Name System), the hosts in the network mapped the easy-to-remember domain name to the IP address and saved it in a shared static file hosts,
and the hosts file was used to realize the domain name in the network management. At first, the Internet was very small, and only this centralized management file was enough.
However, when the number of computers on the Internet is increasing rapidly, the work of managing a host file for all Internet hosts through a central authority will not be possible.
Files will increase over time, so maintaining files in a current and updated form and distributing files to all sites will become very difficult or even impossible to complete, so a DNS server is created.

1.4 Storage location

C:\windows\system32\drivers\etc\

1.5 Changes take effect

Enter the command to make the record take effect immediately without restarting
Win+R->cmd->ipconfig /flushdns

2. hosts under linux

2.1 Introduction to linux hosts

/etc/hosts is the local static host name query table of Linux, which is responsible for the files that quickly resolve IP addresses and domain names in the Linux system

The file name "hosts" may be different for different Linux distributions. For example, the corresponding file for Debian is /etc/hostname

The format of the hosts file is: IP address host name/domain name

2.2 Modify/View

cat vi /etc/hosts

root@glusterfs app]# cat /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost.localdomain localhost6 localhost6.localdomain6
66.66.66.101 glusterfs.green.master
……
[root@glusterfs app]# 

2.3 Then restart the network card to take effect

Guess you like

Origin blog.csdn.net/lqy971966/article/details/107845101