Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the main function of hosts file in Linux system

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article analyzes "what is the main function of hosts files in Linux system?" The content is detailed and easy to understand, and friends who are interested in "what is the main role of hosts files in Linux system" can follow the editor's train of thought to read it slowly and deeply. I hope it will be helpful to everyone after reading. Let's follow the editor to learn the knowledge of "what is the main function of hosts files in Linux system".

1. Hostname:

Whether on the local area network or INTERNET, each host has an IP address to distinguish between this host and the other host, that is to say, the IP address is the house number of the host.

Public network: IP address is not easy to remember, so there is a domain name. Domain names only exist in the public network (INtERNET). Each domain name corresponds to an IP address, but an IP address can have multiple domain names.

Local area network: each machine has a hostname to make it easy to distinguish between hosts and hosts, so you can set a hostname for each machine so that you can access each other in an easy-to-remember way. For example, we can name each machine according to its function in the local area network.

Configuration file related to hostname: / etc/hosts

2. Hostname profile:

The configuration file for hostname is mostly / etc/hosts

The hosts configuration file is a relatively simple way to map host names to IP addresses. But this mapping is only a mapping of the local machine, which means that each machine is independent and none of the computers can access each other through Hostname.

For example:

127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4

127.0.0.1 localhost.localdomain localhost

192.168.1.195 debian.localdomain debian

In general, the content of hosts is about the definition of host name (Hostname). Each behavior is a host, each line is made up of three parts, and each part is separated by spaces. The lines at the beginning of the # sign are not explained by the system.

The first part: network IP address.

The second part: host name. Domain name, notice that there is a half-corner point between the hostname and the domain name.

The second part: the host name (host name alias) is actually the host name.

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

We have three hosts, each doing different things, one for MAIL server, one for FTP server and one for SMB server, so we can design 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 contents of the configuration file above into the / etc/hosts contents of each machine, so that the machines of the three Lans can be accessed through Hostname.

3. The difference between host name (Hostname) and domain name (Domain)

The hostname is the name of the machine itself, and the domain name is used to resolve to IP. But it is worth mentioning that in the local area network, the host name can also be resolved to the IP; for example, we mentioned earlier.

Show hostname:

# Hostname

Root1

The hostname of this host is root1, and no parameters are used to display the hostname of the host for the current operation.

Temporarily set the hostname:

We can use Hostname followed by the hostname, so we can set the hostname of the currently operating host, for example, we want to set the hostname to root2

# Hostname root2

Root2

Setting the hostname through the Hostname tool is only temporary and will not exist the next time the system is rebooted; so if you want to modify the hostname and want to be valid all the time, you should modify the hostname configuration file / etc/hosts as mentioned above.

Display the host IP:

[root@Linuxsir01] # Hostname-I

192.168.10.3

On the Linux system hosts file what is the main role to share here, I hope that the above content can make you improve. If you want to learn more knowledge, please pay more attention to the editor's updates. Thank you for following the website!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report