Hosts file in unix

Source: Internet
Author: User
Tags website server
Article title: hosts file under unix. 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. about/etc/host, host name and IP configuration file

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

In Linux,/etc/hosts is the file that configures the ip address and its corresponding host name. here, the ip addresses of the local host or other hosts and their corresponding host names can be recorded. This configuration file may be different for different linux versions. For example, Debian's corresponding file is/etc/hostname.

2. configuration file

This file can be used to configure the host ip address and the corresponding host name. The role of this file on a server-type linux system cannot be ignored. On a LAN or INTERNET, each host has an ip address, which separates each host and can communicate with each other based on the ip address. But the IP address is not easy to remember, so there is a domain name. In a LAN, each machine has a host name, which is used to distinguish hosts for mutual access.

The configuration file for the Linux host name is/etc/hosts. this file tells the host which domain names correspond to those ip addresses and which ip addresses correspond to those host names:

For example, this definition exists in the file.

192.168.1.100 linumu100 test100

Suppose 192.168.1.100 is a website server. enter http: // linumu100 or http: // test100 on the webpage to open the web page 192.168.1.100.

Generally, this file records the local ip address and host name:

127.0.0.1 localhost. localdomain localhost

3. configuration file format description

Generally, the content of/etc/hosts is similar to the following:

127.0.0.1 localhost. localdomain localhost

192.168.1.100 linmu100.com linmu100

192.168.1.120 ftpserver ftp120

Generally, each hosts file 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 or domain name;

Part 3: host name alias;

Of course, each line can also be two parts, namely the host IP address and host name; for example, 192.168.1.100 linmu100.

Here we can slightly explain the differences between the host name (hostname) and Domain name (Domain): the host name is usually used in the LAN. through the hosts file, the host name is resolved to the corresponding ip address; the domain name is usually used on the internet, but if the local machine does not want to use domain name resolution on the internet, then you can change the hosts file and add your own domain name resolution.

4. what problems can the/hosts file help solve?

4.1 slow remote logon to linux hosts

Sometimes the client wants to remotely log on to a linux host, but it will wait a long time after entering the password. this is because the linux host needs to resolve the ip address when returning information, if you add the IP address of the client to the hosts file of the linux host, then remote linux login from the client will become very fast.

Note: remote logon is not only about ssh, but also about mysql remote logon or file sharing query.

4.2 Dual-host interconnection

When the two hosts are connected by two machines, you must set your own ip address and add your own ip address and host name to the hosts file of the other host.

5. host name modification tool hostname;

In fact, there is also a dedicated tool for modifying the host name, that is, the hostname

Hostname-show or set the system's host name

Show host name:

# Hostname

Linmu100

The host name of this host is linmu100, and the host name of the current host is displayed without parameters;

Set the host name temporarily:

# Hostname test100

# Hostname note: the host name is displayed.

Test100

Using the hostname tool to set the host name is only temporary. the host name will not exist the next time the system is restarted;

Display host IP address:

# Hostname-I

192.168.1.100

 

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.