Linux hostname has been developing for a long time. Here I will share my personal understanding. Next I will talk about Linux hostname. Today, I began to write network documents again. I first wrote a smaller trainer and planned a larger basic network document. I felt like I could not start with my own plan, there is too much content, and everyone is reading too tired. Therefore, we can split large documents into small documents, so it is not too tired to write and read. If you want to know more details, I will combine these small documents to become a series of documents.
1. What is the Linux 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. But the IP address is not easy to remember, so there is a domain name. The domain name only exists in the INtERNET (except for the LAN experiment for the purpose of the experiment). Each domain name corresponds to one IP address, but one IP Address can correspond to multiple domain names. The domain name type is Linux sir.org;
What is the host name used? In a LAN, each machine has a host name for easy distinction between the host and the host, you can set a host name for each machine, to facilitate mutual access in a way that is easy to remember. For example, we can name each machine based on its functions in the LAN. Configuration file related to the Host Name:/etc/hosts;
2. Linux host name configuration file;
Most of The Host Name configuration files are/etc/hosts; hosts-The static table lookup for Linux hostname host name query static tables). Due to The large number of Linux releases, configuration files related to host names are sometimes different. Now let's talk about the common version of the Host Name configuration file;
2.1 Linux host name setting file/etc/hosts explanation;
Fedora/Redhat or ora/Redhat-based release. The host name configuration file is/etc/hosts Debian or Debian-based release, the host name configuration file is/etc/Linux hostname and/etc/hosts Slackware. The host name configuration file is/etc/hosts. Let's read the content of/etc/hosts, see what this file is used.
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 Linux hostname. Note: there is also a/etc/Linux hostname File In debian. This file writes the local host name directly, but it must be consistent with the local host name in/etc/hosts.
The content of/etc/hosts is generally similar to the following: 127.0.0.1 localhost. localdomain localhost 192.168.1.195 debian. localdomain debian Note: Generally, the hosts content defines the Host Name (Linux hostname). Each host acts as 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 the host name and domain name, such as localhost. localdomain Part 2: Host Name (host name alias), which 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
127.0.0.1 is the loop 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 loop address for testing. Why do I need to define a domain name? In fact, it is easy to understand. For example, we have three hosts, each of which does different things. One is a MAIL server, the other is an FTP server, and the other is an SMB server, so we can design the 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 content of the above configuration file into the/etc/hosts content of each machine separately, so that the three LAN machines can be accessed through Linux hostname.
2.2 differences between the host name (Linux hostname) and Domain name (Domain;
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;
2.3 The reason why machines on the LAN cannot access each other through host names;
Some may say that my Linux hostnames cannot communicate with each other. In fact, this problem is also simple. We have mentioned a simple solution. It is to make all hosts in the LAN have a common and contain the/etc/hosts files of all hosts;
The other solution is to create a lan dns server. If you have few hosts, simply use the simple method mentioned above, I will introduce this topic in future documents; however, it is worth mentioning that any server is based on the principle of efficiency first.
For example, if we have two machines in the LAN, do we still need a DNS server? No matter how it is solved, the most efficient solution is to solve the problem. We cannot describe how advanced DNS is. If the DNS service is for the Internet, you have to do it without doing anything. Right?
3. Host Name modification tool Linux hostname;
In fact, there is also a dedicated tool for modifying the host name, that is, Linux hostname. I think if you use this tool to modify the host name, it is better to directly modify/etc/hosts; you can view the help of hosname -- help or man Linux hostname. Here we only talk about simple usage. the Linux hostname tool is used to display and set the system host name. For more information, see the following document.
Example: show the Host Name: [root @ linuxsir01 ~] # Linux hostname linuxsir01 the host name is linuxsir01, and the parameter is not added to display the Host Name of the current operation. Temporary host name setting: We can use Linux hostname to connect to the host name, in this way, you can set the host name for the current operation.
For example, we want to set the host name to linuxsir02; [root @ linuxsir01 ~] # Linux hostname linuxsir02 [root @ linuxsir01 ~] # Linux hostname note: the host name linuxsir02 is displayed. It is only temporary to set the host name through the Linux hostname tool. The host name will not exist the next time you restart the system. Therefore, you want to modify the host name, if you want to remain valid, use the aforementioned modification of the Host Name configuration file/etc/hosts; display Host IP Address: display the IP address of the current host name, you can use the-I parameter; [root @ linuxsir01 ~] # Linux hostname-i192.168.1.3
4. Matters not covered in this article;
Sometimes, when we log on to the desktop, We will prompt that the Linux hostname cannot be found. In this case, you need to modify/etc/hosts to add a host name for your machine; first use ifconfig-a to view the host's IP address, and then specify the host name for the IP address of your host;
I haven't written a document for many days, not because I don't have time, but because I tested some hardware I didn't use. I want to write a few hardware documents. However, due to restrictions, the hardware documents were not written out, and the originally planned basic network system files were separated.
I 've been wondering these days if I 've made a mistake? Although the effort failed, I did not say that I did not work hard, but I did not get what I needed. It seems that everything is not smooth sailing. As long as it is supported, we may want what we want.
- Successful commercial behaviors and profit models of Linux open-source software
- Six advantages of Linux
- Use Magic Linux release
- Linux rescuev repair mode logon across the Console
- Linux-guided installation in GRUB Command Line Mode