Linux host name Hostname

Source: Internet
Author: User
Article Title: Linux host name Hostname details. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.

  1. What is a 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. Domain Name types such as linuxsir.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. Host Name configuration file;

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

Hosts-The static table lookup for host name (host name query static table );

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 host name configuration file/etc/hosts explanation;

Ora/Redhat or a release package based on Fedora/Redhat. The host name configuration file is/etc/hosts.

Debian or Debian-based release. The host name configuration file is/etc/hostname and/etc/hosts.

The Slackware host name configuration file is/etc/hosts.

Let's read the content of/etc/hosts and 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 hostname.

Note: there is also a/etc/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 (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, such as localhost. localdomain

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

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 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.

2.2 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;

2.3 The reason why machines on the LAN cannot access each other through host names;

Some may say that my 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 hostname;

In fact, there is also a dedicated tool for modifying the host name, that is, 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 hostname. Here we only talk about simple usage;

The hostname tool is used to display and set the system host name. For more information, see the following foreign document;

Hostname-show or set the system's host name

Example:

* Display Host Name:

[Root @ linuxsir01 ~] # Hostname

Linuxsir01

The host name of this host is linuxsir01, and the Host Name of the current host is displayed without parameters;

* Temporarily set the Host Name:

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 linuxsir02;

[Root @ linuxsir01 ~] # Hostname linuxsir02

[Root @ linuxsir01 ~] # Hostname note: the host name is displayed.

Linuxsir02

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:

Displays the IP address of the current host name. You can use the-I parameter;

[Root @ linuxsir01 ~] # Hostname-I

192.168.1.3

  4. Matters not covered in this article;

Sometimes, when we log on to the desktop, We will prompt that the 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 your host's IP address.

Related Article

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.