1, about/etc/host, hostname and IP configuration file
Hosts-the static table lookup for host name (host-Name query-still tables)
Hosts file is a Linux system responsible for the rapid resolution of IP address and domain name files, in ASCII format in the "/etc" directory, the file name "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 can query the file to resolve the IP address corresponding to a host name, otherwise it will need to use the DNS service program to resolve. 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 you can explain the difference between host name (hostname) and domain name: hostname is usually used in LAN, through Hosts file, host name is resolved to corresponding IP, domain name is usually used on the internet, However, if the computer does not want to use the domain name resolution on the Internet, you can change the hosts file to join your own domain name resolution.
4./hosts files can help resolve what problems
4.1 Remote login to Linux host too slow problem
Sometimes the client wants to telnet to a Linux host, but each login password will wait for a long time to enter, this is because the Linux host in the return of information need to resolve IP, if the hosts in the Linux host file in advance to join the client's IP address, Then telnet to Linux from the client will become 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
Linux hostname after a long period of development, here I publish a personal understanding, the following is the way to talk about the operation of Linux hostname. Today began to write online documents, first write a small bit of practice practiced hand, originally planned a relatively large network of basic documents, one of their own planning to feel the beginning, too much content, we also read tired, so the big documents into small documents, so write up not tired, and read more not tired. If you want to know more, I will combine these small documents so that I can become a series of documents.
1, what is the name of the Linux hostname;
Whether on the LAN or the Internet, each host has an IP address to differentiate between this host and its host, that is, the IP address is the host's number. But the IP address is not easy to remember, so there is a domain name. Domain name is only in the public network (the INtERNET) exists (for experimental purposes, LAN domain network experimental), each domain name corresponds to an IP address, but an IP address can have a number of domain names. Domain Name Type Linux sir.org such a;
What is the hostname used for? In a local area network, each machine has a host name, for the host and the host to facilitate the separation, you can set the host name for each machine, in order to easily remember the way to access each other. For example, we can be named according to the function of each machine in LAN. Hostname-related configuration file:/etc/hosts;
2. linux hostname configuration file;
The hostname configuration file is mostly/etc/hosts; hosts-the static table lookup for Linux hostname (hostname query static table); Because of the large number of Linux distributions, the configuration files associated with hostnames are sometimes different. Now let's talk about the common version of the hostname configuration file;
2.1 Linux host name file/etc/hosts commentary;
Fedora/redhat or Fedora/redhat-based distribution, the hostname profile is/etc/hosts Debian or Debian-based distribution, and the hostname profile is/etc/linux hostname and/ Etc/hosts slackware hostname profile is/etc/hosts so let's read/etc/hosts's content and see what this file is for.
The hosts configuration file is the method used to map the host name to the IP address, which is relatively simple. But this mapping is only a local machine mapping, which means that each machine is independent, and all computers can not be accessed from each other through the Linux hostname. Note: There is also a/etc/linux hostname file in Debian, which simply writes the local hostname, but is consistent with the local hostname in/etc/hosts.
/etc/hosts content generally has the following similar content: 127.0.0.1 localhost.localdomain localhost 192.168.1.195 debian.localdomain Debian Note: In general the content of the hosts is about the hostname (Linux hostname) definition, each behavior of a host, each line consists of three parts, each part separated by a space. Where the # starts with a line that is not explained by the system.
Part I: Network IP address; second part: hostname. Domain name, note that there is a half-width point between the hostname and the domain name, such as the second part of the Localhost.localdomain: hostname (hostname alias), is actually the hostname; Of course, each line can also be two parts, is the host IP address and host name, such as 192.168.1.195 Debian
127.0.0.1 is a loopback address, such as we do not want to let the other machine on the LAN to see our test network program, you can use loopback address to test. Why do you need to define a domain name? In fact, it is simple to understand, for example, we have three hosts, each to do a different thing, a mail server, an FTP server, an SMB server, so we can design Linux hostname;
The contents of this configuration file are written into the/etc/hosts content of each machine, so that the three LAN machines can be accessed through the Linux hostname.
2.2 The difference between hostname (Linux hostname) and domain name (domains);
Hostname is the name of the machine itself, the domain name is used to resolve to the IP. But it is worth saying that in the local area network, the hostname can also be resolved to the IP, such as the example we said earlier;
2.3 Local Area network machine, cannot pass the host name exchange of visits reason;
Some brothers may say that my Linux hostname can not exchange visits with each other, in fact, this is also a simple problem, we have already mentioned a simple solution. is to let all the hosts in the LAN have a common, and contains all the hosts of the/etc/hosts file;
Another is to do the solution is to do LAN DNS server, if your host is particularly small, just use the simple method mentioned above, how to do the DNS server, I will be in the future of the document presentation; But I should mention that any server is based on the principle of efficiency first.
For example, we have two machines in the LAN, do we still need to do DNS server? No matter how the solution, the ultimate is the most efficient way to solve the problem, we can not explain how advanced DNS. If DNS is for an extranet service, then say otherwise, do not do also have to do. Right?
3, hostname modification tool Linux hostname;
In fact, the hostname of the modification also has a special tool, is the Linux hostname; I think if you use this tool to modify the hostname, it is better to modify the/etc/hosts directly, you can view the Hosname--help or man Linux hostname help. Here we only say simple usage; The Linux hostname tool is used to display and set the system hostname, look at the following foreign language; Linux hostname-show or set, the system ' s host name
Example: Display hostname: [[email protected] ~]# Linux hostname Linuxsir01 The host name of this host is Linuxsir01, no parameter is the host name of the host that is used to display the current operation; temporarily set hostname: we can use The Linux hostname is followed by the hostname so that the host name of the host for the current operation can be set.
For example, we want to set the hostname to Linuxsir02;[[email protected] ~]# Linux hostname linuxsir02[[email protected] ~]# linux hostname Note: Display hostname linuxsir02 through the Linux hostname tool to set the hostname is only temporary, the next time you restart the system, this hostname will not exist; so you want to modify the hostname, want to always be valid, or modify the hostname configuration file with the previous name/etc/hosts Display Host IP: Displays the IP of the current hostname, which can be used with the-i parameter; [[email protected] ~]# Linux hostname-i192.168.1.3
4, this article does not do the matter;
Sometimes when we log on to the desktop, we will be prompted to find the Linux hostname, when you want to do is to modify the/etc/hosts, for your machine to add a host name, first use Ifconfig-a to view the host's IP address, and then put your host's IP address, specify the host name;
I haven't written a document in days, not because I don't have time, but I have tested some hardware I haven't used. Want to write a few hardware documents, but due to constraints, hardware documents did not write out, but also the originally planned network infrastructure system files to be isolated.
These days, I've been wondering if I'm doing this wrong? Things have passed, although efforts have not been successful, but can not say that I did not work, but the results did not get what I need. It seems that doing anything is not smooth sailing. As long as it is supported, it is possible for us to think what we want.
/etc/hosts file configuration method under Linux operating system