/etc/hosts file configuration method under Linux operating system

Source: Internet
Author: User
Tags domain name server

1, about/etc/host, hostname and IP configuration file
Hosts-the static table lookup for host name (host-Name query-still tables)
The Hosts file is a file that is responsible for the fast resolution of IP addresses and domain names in the Linux system, and is stored in the "/etc" directory in ASCII format.
The file name is "hosts" (different versions of Linux, this configuration file may also be different.) For example, Debian's counterpart file is/etc/hostname).
The Hosts file contains mappings between IP addresses and host names, and also includes aliases for host names. In the absence of a domain name server,
All network programs on the system resolve the IP address that corresponds to a host name by querying the file, or you need to use a DNS service program to resolve it.
You can often add common domain names and IP address mappings to the Hosts file for quick and easy access.

2. Configuration files
This file can be configured with the host IP and the corresponding hostname, which is not negligible for the server type Linux system.
On the LAN or the Internet, each host has an IP address that separates each host and can communicate based on IP.
But the IP address is not easy to remember, so there is a domain name. In a local area network, each machine has a host name, which is used to differentiate the host and facilitate mutual access.
The relevant configuration file of the Linux hostname is/etc/hosts; This file tells the host which domain names correspond to those IPs, and which IP addresses those host names:
Like there's a definition in the file.
192.168.1.100 linumu100 test100
Assuming 192.168.1.100 is a Web server, entering http://linumu100 or http://test100 on a Web page will open the 192.168.1.100 Web page.
Typically, this file first records the IP and hostname of the machine:
127.0.0.1 localhost.localdomain localhost

3. Configuration file Format Description
General/etc/hosts content generally has the following similar content:
127.0.0.1 localhost.localdomain localhost
192.168.1.100 linmu100.com linmu100
192.168.1.120 Ftpserver ftp120
In general, each behavior of the hosts file is a host, each line consists of three parts, and each part is separated by a space. Where the # starts with a line that is not explained by the system.
The Hosts file has the following format:
IP address host name/domain name
The first part: Network IP address;
Part Two: hostname or domain name;
The third part: hostname alias;

Of course, each line can also be two parts, that is, the host IP address and host name, such as 192.168.1.100 linmu100.
Here's a little explanation of the difference between the hostname (hostname) and the domain name: the host name is usually used on the LAN,
With the Hosts file, the host name is parsed to the corresponding IP, and the domain name is usually used on the internet, but if the computer does not want to use domain name resolution on the Internet,
You can then change the Hosts file to add your own domain name resolution.
4. The Hosts file can help resolve which issues
4.1 Remote login to Linux host too slow problem
Sometimes the client wants to telnet to a Linux host, but it will wait a long time for the password to enter after each login, because the Linux host needs to parse the IP when returning the information.
If the Hosts file of the Linux host is added to the client's IP address in advance, then telnet to Linux from the client becomes very fast.
NOTE: Remote login here is not just ssh, it may be MySQL remote login, or file sharing query.
4.2 Dual-Machine interconnect
When the two hosts are only two-computer interconnection, both hosts need to set their own IP, while in the other's Hosts file to add their own IP and host name.
5, the hostname modification tool hostname;
In fact, the hostname of the modification also has a special tool, that is hostname
Hostname-show or set the system ' s host name
Display host Name:
# hostname
linmu100
The host name of this host is linmu100, and no parameter is used to display the host name of the current host;
Temporarily set host name:
# hostname test100
# hostname Note: Display host name
test100
Using the Hostname tool to set the hostname is only temporary, the next time you restart the system, the host name will not exist;
Show host IP:
# hostname-i
192.168.1.100

/etc/hosts file configuration method under Linux operating system

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.