Linux Modify/etc/hosts

Source: Internet
Author: User

Directory structure

    • Directory structure
    • Hosts file
    • Hosts format configuration
      • Hosts file format
    • Hosts file role

Hosts file

Hosts--the static table lookup for host name (host name query for still tables).
The Hosts file is a file that is responsible for fast resolution of IP addresses and domain names in the Linux system, and is stored in the/etc/directory in ASCII format. The Hosts file contains a mapping between the IP address and the host name, and also includes the host alias. In the absence of a domain name resolution server, all network programs on the system can query the file to resolve the IP address corresponding to a host name, otherwise it will need to be resolved by using a DNS service program. Fast and easy access can be achieved by adding common domain names and IP address mappings to the Hosts file.
Priority: DNS Cache > Hosts > DNS service

Hosts format configuration

The Hosts file can be configured with the host IP and the corresponding host name. On a local area network or on the World Wide Web, each host has an IP address that separates each host and can communicate according to the IP. But the IP address does not accord with the human brain's memory law, therefore has appeared the domain name, for example Www.baidu.com. In a local area network, each machine has a hostname, which is used to differentiate the host and facilitate mutual access.

Hosts file format
ip地址   主机名/域名   (主机别名)

the difference between host name and domain name is :

    • The hostname is usually used within the LAN, and the host name is resolved to the corresponding IP through the hosts file.
    • The domain name is usually used on the Internet, but the priority is lower than the content in the Hosts file, so if you don't want to use domain name resolution on the Internet, you can change your hosts file to include your own domain name resolution.
Hosts file role

One of the main functions is: Offline environment simulation, communication between the two sides in the same LAN want to access through the Internet domain name, then 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:

Linux Modify/etc/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.