Linux under the Hosts file 1, host name: both on the LAN or the Internet, each host has an IP address, is to distinguish between this host and the host, that is, the IP address is the host's number. Public network: The IP address is not easy to remember, so there is a domain name. Domain names exist only in the public network (the INtERNET), each domain name corresponds to an IP address, but an IP address can have multiple domain names. LAN: 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 profiles:/etc/hosts 2, hostname profile: The host name of the configuration file is mostly the/etc/hosts hosts configuration file is used to map the host name to the IP address method, this method is relatively simple. But this mapping is only a local machine mapping, which means that each machine is independent, and all computers can not access each other through hostname. Example: 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4127.0.0.1 localhost.localdomain localhost192.168.1.195 Debian.localdomain Debian in general the content of the hosts is about the host name (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. The first part: Network IP address. Part two: hostname. Domain name, note that there is a half-width point between the host name and the domain name. The second part: hostname (hostname alias), is actually the host name. Of course, each line can also be two parts, that is, the host IP address and hostname; For example, 192.168.1.195 Debian we have three hosts, each do a different thing, a mail server, an FTP server, an SMB server, So we can design hostname;127.0.0.1 localhost.localdomain localhost192.168.1.2 ftp.localdomain ftp192.168.1.3 Mail.localdomain mail192.168.1.4 smb.localdomin SMB writes the contents of this configuration file to the/etc/hosts content of each machine, so that the three LANcan be accessed through the hostname. 3, hostname (Hostname) and domain name (domains) The difference 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 LAN, the host name can also be resolved to the IP, such as the example we mentioned above; show hostname: # HOSTNAMEROOT1 The hostname of this host is ROOT1, and no parameter is the host name of the host that is used to display the current operation. Temporarily set host name: We can use Hostname after the hostname, so that we can set the host name of the current operation, such as we want to set the hostname to root2;# Hostname Root2root2 through the Hostname tool to set the hostname is only temporary, This host name will not exist the next time you reboot the system, so you want to modify the hostname, you want to always be valid, or you can modify the hostname configuration file/etc/hosts with the previous name; display host ip:[[email protected] ~]# Hostname- i192.168.10.3
A detailed description of the Hosts file under Linux