In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
In this issue, the editor will bring you about how to understand the Linux hostname hostname configuration file / etc/hosts. The article is rich in content and analyzes and narrates it from a professional point of view. I hope you can get something after reading this article.
1. What is the Linux 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. But the IP address is not easy to remember, so there is a domain name. Domain names only exist in the public network (INtERNET) (except for experimental local area networks for experimental purposes). Each domain name corresponds to an IP address, but an IP address can have multiple domain names. Domain name type Linux sir.org
What is the hostname used for? In a local area network, each machine has a host name, which is used to distinguish between hosts and hosts, so you can set the host name 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. Linux hostname profile
The configuration files for hostnames are mostly / etc/hosts; hosts-The static table lookup for Linux hostname (hostname query static table); and the configuration files related to hostnames are sometimes different due to the large number of Linux distributions. Now let's talk about the common version of the hostname profile
2.1 Linux hostname configuration file / etc/hosts
Fedora/Redhat or Fedora/Redhat-based packaged distribution, hostname configuration file is / etc/hosts Debian or Debian-based packaged distribution, hostname configuration file is / etc/Linux hostname and / etc/hosts Slackware hostname configuration file is / etc/hosts, so let's read the contents of / etc/hosts and see what this file is used for.
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 Linux hostname. Note: there is also a / etc/Linux hostname file in debian, which just writes the local host name directly, but it should be consistent with the local host name in / etc/hosts.
The content of / etc/hosts 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 hosts is about the definition of host name (Linux hostname). Each behavior is a host, each line is composed 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, note that there is a half-corner between the host name and the domain name, such as the second part of localhost.localdomain: host name (host name alias), which is actually the host name; of course, each line can also be two parts, that is, the host IP address and the host name; for example, 192.168.1.195 debian
127.0.0.1 is the loopback address. For example, if we do not want other machines in the LAN to see the network program we are testing, we can use the 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 doing different things, one for MAIL server, one for FTP server and one for SMB server, so we can design Linux 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 Linux hostname.
2.2 differences between hostname (Linux 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.
2.3 the reason why the machines in the LAN cannot access each other through the host name
Some may say that my Linux hostname cannot visit each other. In fact, this is also a simple problem. We have already mentioned a simple solution. Is to make all hosts in the LAN have a common / etc/hosts file that contains all hosts.
Another solution is to do a local area network DNS server, if you have very few hosts, just use the simple method mentioned above; how to do a DNS server, I will explain in a later document; but it is worth mentioning that any server is based on the principle of efficiency first.
For example, if there are two machines in the local area network, is it necessary to do DNS servers?
3. Hostname modification tool Linux hostname
In fact, there is also a special tool for host name modification, that is, Linux hostname. I think if you use this tool to modify the host name, it is not as convenient to modify / etc/hosts directly; you can check the help of hosname-help or man Linux hostname. Here we will only talk about simple usage; the Linux hostname tool is used to display and set the hostname of the system, see the following foreign language; Linux hostname-show or set the system's hostname
Example: display hostname: [root@linuxsir01 ~] # Linux hostname linuxsir01 the hostname of this host is linuxsir01, and the hostname of the host used to display the current operation without parameters; temporarily set the hostname: we can use Linux hostname followed by the hostname, so we can set the hostname of the host of the current operation.
For example, if you want to set the hostname to linuxsir02; [root@linuxsir01 ~] # Linux hostname linuxsir02 [root@linuxsir01 ~] # Linux hostname Note: displaying the hostname linuxsir02 sets the hostname through the Linux hostname tool is only temporary, and the next time the system is rebooted, this hostname will not exist
To wait for permanent effect, use the modified hostname configuration file / etc/hosts; mentioned above to display the host IP: display the IP of the current hostname, using the-I parameter; [root@linuxsir01 ~] # Linux hostname-i192.168.1.3
4. Unfinished business
Sometimes when you log in to the desktop, you will be prompted that the Linux hostname cannot be found. Modify / etc/hosts to add a host name.
First use ifconfig-a to check the IP address of the host, and then assign the IP address of your host to the host name.
After doing so, there will be no problem.
The above is the editor for you to share how to understand the Linux hostname hostname configuration file / etc/hosts, if you happen to have similar doubts, you might as well refer to the above analysis to understand. If you want to know more about it, you are welcome to follow the industry information channel.
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.