Set hostname and host mapping

set hostname

For the convenience of memory. You can give the hostname to the linux system, or you can modify the hostname as needed.
Command hostname to view the hostname.
Modify the hostname
after entering vim /etc/hostname
Please add a picture description
. After the modification, restart it to take effect

Set host mapping

How to ping a linux system through the host name
Enter
[root@bskkk ~]# vim /etc/hosts in the linux environment
Please add a picture description
, directly add your own ip and host name at the end, save and exit, and directly pass
in the window environment
hostname will find

Please add a picture description

We only need to find c:\windows\System32\drivers\etc\hosts and add the ip address host name after entering,
then we can ping successfully

Analysis of host name resolution process

What are hosts?
A text file used to record the mapping relationship between IP and hostname (host name)
What is the DNS?
DNS is the domain name system
, which is a distributed database on the Internet that maps domain names and IP addresses to each other.

Application example:
For example, what will happen if the user enters www.baidu.com in the browser?

1. The browser will first check whether there is an IP address for the domain name resolution in the browser cache, and if so, it will first call this IP to complete the resolution. If not, the DNS resolver cache is checked. If the IP is returned directly, the analysis is completed. These two caches can be understood as local resolver caches

2. If the local resolver cache does not find the corresponding mapping. It will check whether the corresponding domain name IP mapping is configured in the hosts file in the system. If there is, the parsing is complete and returns

3. If the corresponding IP is not found in the local resolver cache and the hosts file, it will go to the public domain name server DNS to search for the resolution domain. If it is not found, a subdomain does not exist or other error will be generated.

Please add a picture description

This picture does not have a browser cache step, because it may be a direct ping

In addition:
Generally speaking, when a computer successfully visits a website for the first time, the browser or operating system will cache its IP address (DNS resolution record) within a certain period of time. For example, you can enter ipconfig /displayns in the cmd
window
// DNS domain name resolution cache records will be displayed
ipconfig /flushdns
//Manually clear the DNS cache

Guess you like

Origin blog.csdn.net/2202_75623950/article/details/131030108