In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-14 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
Today, I will talk to you about the use of Linux / etc/hosts files, which may not be well understood by many people. In order to make you understand better, the editor has summarized the following contents for you. I hope you can gain something according to this article.
The function of hosts file: establish an associated "database" between some commonly used URL domain names and their corresponding IP addresses. When users enter a URL that needs to be logged in in the browser, the system will first automatically find the corresponding IP address from the Hosts file. Once found, the system will immediately open the corresponding web page. If it is not found, the system will submit the URL to the DNS domain name resolution server for IP address resolution.
Configuration method of / etc/hosts file under Linux operating system
Hosts file
Hosts-- the static table lookup for host name (hostname query static table).
The hosts file is a file responsible for the rapid resolution of ip addresses and domain names on the Linux system, which is saved in the / etc/ directory in ascii format. The hosts file contains the mapping between the ip address and the host name, as well as the alias of the host. In the absence of a domain name resolution server, all network programs on the system resolve the ip address corresponding to a host name by querying the file, otherwise they need to use dns service programs to solve the problem. Through the commonly used domain name and ip address mapping can be added to the hosts file to achieve fast and convenient access.
Priority: dns cache > hosts > dns service
Hosts format configuration
The hosts file can configure the host ip and the corresponding hostname. On the local area network or the World wide Web, each host has an ip address, which distinguishes each host and can communicate according to the ip. But the Ip address does not conform to the memory rule of the human brain, so there are domain names, such as www.baidu.com. In a local area network, each machine has a hostname, which is used to distinguish between hosts and facilitate mutual access.
Hosts file format
Ip address hostname / domain name (host alias)
The difference between a hostname and a domain name is:
The host name is usually used in the local area network, and the host name is resolved to the corresponding ip through the hosts file.
Domain names are usually used on internet, but their priority is lower than those in hosts files, so if you don't want to use domain name resolution on internet, you can change your hosts file and add your own domain name resolution.
The function of hosts file
One of the main functions is: offline environment simulation, if the two sides of communication want to access each other through the domain name on internet in the same local area network, they only need to modify their own / etc/hosts file content.
For example, modify the ip of www.baidu.com to 127.0.0.1:
After modifying / etc/hosts, the effect of ping Baidu is as follows:
The configuration file for Linux hostnames is / etc/hosts;. This file tells the host which domain names correspond to those ip and which hostnames correspond to which ip:
For example, there is such a definition in the file.
192.168.1.100 linumu100 test100
Assuming that 192.168.1.100 is a web server, typing http://linumu100 or http://test100 in the page will open the page of 192.168.1.100.
Typically, this file first records the ip and hostname of the machine:
127.0.0.1 localhost.localdomain localhost
3. Description of configuration file format
The contents of general / etc/hosts are generally similar to the following:
127.0.0.1 localhost.localdomain localhost192.168.1.100 linmu100.com linmu100192.168.1.120 ftpserver ftp120
In general, each behavior of a hosts file is a host, each line is made up of three parts, and each part is separated by spaces. The lines at the beginning of the # sign are not explained by the system.
The format of the hosts file is as follows:
IP address hostname / domain name
Part I: network IP address
Part II: hostname or domain name
Part III: host name alias
Of course, each line can also be in two parts, the host IP address and the host name; for example, 192.168.1.100 linmu100.
The difference between host name (hostname) and domain name (Domain) can be explained slightly here: the host name is usually used in the local area network. Through the hosts file, the host name is resolved to the corresponding ip; domain name, which is usually used on the internet. But if the local machine does not want to use the domain name resolution on internet, you can change the hosts file and add your own domain name resolution.
After reading the above, do you have any further understanding of the purpose of the / etc/hosts file in Linux? If you want to know more knowledge or related content, please follow the industry information channel, thank you for your support.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.