Linux hosts file details,

Source: Internet
Author: User

Linux hosts file details,

1. Host Name:

Each host has an IP address, whether on the LAN or the INTERNET, to distinguish between the host and the other host, that is, the IP address is the house number of the host.

Public Network: the IP address is not easy to remember, so there is a domain name. The domain name only exists in the INtERNET,Each domain name corresponds to one IP address, but one IP Address can correspond to multiple domain names.

Lan: Each machine has a host name, which is used to distinguish between the host and the host. You can set a host name for each machine to facilitate mutual access in an easy-to-remember way. For example, we can name each machine based on its functions in the LAN.

Configuration file related to the Host Name:/etc/hosts

2. Host Name configuration file:

Most of the Host Name configuration files are/etc/hosts

The hosts configuration file is used to map host names to IP addresses. This method is relatively simple. However, this ing is only the ing of local machines. That is to say, each machine is independent and all computers cannot access each other through Hostname.

For example:

127.0.0.1 localhost. localdomain localhost4 localhost4.localdomain4

127.0.0.1 localhost. localdomain localhost

192.168.1.195 debian. localdomain debian

Generally, the hosts content defines the Host Name (Hostname). Each act is a host. Each line consists of three parts, separated by spaces. The line starting with # is not explained by the system.

Part 1: network IP address.

Part 2: Host Name. Domain Name. Note that there is a halfwidth between host name and domain name.

Part 2: Host Name (host name alias) is actually the host name.

Of course, each line can also be two parts, namely the Host IP address and host name; for example, 192.168.1.195 debian

 

 

We have three hosts, each of which does different things. One is the MAIL server, the other is the FTP server, and the other is the SMB server, so we can design the Hostname in this way;

127.0.0.1 localhost. localdomain localhost

192.168.1.2 ftp. localdomain ftp

192.168.1.3 mail. localdomain mail

192.168.1.4 smb. localdomin smb

Write the content of the above configuration file into the/etc/hosts content of each machine separately, so that the machines on the three LAN can access it through Hostname.


3. Differences between host names and Domain names

The host name is the name of the machine, and the domain name is used to resolve the IP address. But it is worth mentioning that in the LAN, the host name can also be resolved to the IP address; for example, the example we mentioned above;

 

Show Host Name:

# Hostname

Root1

The host name of this host is root1, and the parameter is not added to display the Host Name of the current operation.

Set the host name temporarily:

We can use Hostname to connect to the host name, so that we can set the host name for the current operation. For example, we want to set the host name to root2;

# Hostname root2

Root2

Using the Hostname tool to set the host name is only temporary. The host name will not exist the next time you restart the system. Therefore, if you want to change the host name to always be valid, modify the host name configuration file/etc/hosts as mentioned earlier;

Display Host IP Address:

[Root @ Linuxsir01 ~] # Hostname-I

192.168.10.3

Http://www.cnblogs.com/xiaoit/p/3989026.html

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.