Hosts files in Linux

Source: Internet
Author: User

Turn: http://tech.techweb.com.cn/thread-437185-1-1.html

 

1. About/etc/host, host name and IP configuration file 9'6 V: L + q "X (f''
Hosts-the static table lookup for host name (host name query static table)
: Z. Y3 V/{4 m'p3 G & E :~ 0 w $ tlinux/etc/hosts is the file that configures the IP address and its corresponding host name. Here, the IP address of the local host or other hosts and its corresponding host name can be recorded. This configuration file may be different for different Linux versions. For example, Debian's corresponding file is/etc/hostname.
! ? % K, s # Z8 u * | 9g; @/_ 2. Configuration File
0 z! U6 \ 9 p, f * j (] $ o/U '~ 7 | the 'z "o file can be used to configure the Host IP address and the corresponding host name. It cannot be ignored for server-type Linux systems. 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.
1 B7 I % Q3 u7 E & O2 xlinux host name configuration file is/etc/hosts; this file tells the host which domain names correspond to those IP addresses and the host names correspond to which IP addresses: 4 I 'z (U/C3 Z) q
For example, the file contains the definition/W1 _ 2 A "L $ A-S *} 3 H8 ^ $ Q1 F
192.168.1.100 linumu100 test100 + O4 R2 A # W/A: _ 3 y #\
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. /P; q0 H5 E: C. G0 E; P0 w-z) a' H
Generally, this file records the local IP address and Host Name:
/_ + Q9 [* A "y0 Y4 B & m127.0.0.1 localhost. localdomain localhost7 a' R1 g C6 D: U-[% L * h y/T8 u
3. configuration file format description
& |) C $ y! G % H6 K. ^ 1 {+ T generally/etc/hosts has the following similar content:
J2 C * G6 D4 B (X! P #] 127.0.0.1 localhost. localdomain localhost + y0 m3 L) u'o & P-I * l ,?
192.168.1.100 linmu100.com linmu100 "] 3 @ 1 W &]-o $ a z ;{
192.168.1.120 ftpserver ftp1208 F # M7 F, B! Y + A.]) P
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. : G-U5 o # Z. O "} _-B3 m
Part 1: network IP address; * \ 'z-H (D/P & P: w6}/T
Part 2: Host Name or domain name;
2} (Z3 d $ y0 x9 _ 9 V Part 3: Host Name alias; * w # [* W7 L6 L
Of course, each line can also be two parts, namely the Host IP address and host name; for example, 192.168.1.100 linmu100. 5 C7 C9 C7 @ 'O: _ 1 B + E' _ X4 s
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.
0 k) B! What problems can the z A % E4./hosts file help solve?
* K0 A. K0 D (A3 v4.1 slow remote logon to Linux Hosts
/T5 f * V6 I. B-M (D-z -~ & S6 g sometimes the client wants to remotely log on to a Linux host, but it will wait for a long time after entering the password. This is because the Linux host needs to parse the IP address when returning the 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.
9 H & ^ 4 W1 t/u Y2 G note: the remote logon mentioned here is not only SSH, but also MySQL remote logon or file sharing query. 'W/l5 [! F3 B) O "Y
4.2 dual-host interconnection 8 O3 M6 [: Q8 R. \ 9} % F (B! K
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.
9 N ;~ 9 W, m) f'f5. hostname modification tool;
,~ % I # D0 @ 5 J $ L $ l "g in fact, there is also a dedicated tool for modifying the host name, that is, hostname
; [# D, L6 J8 F8 K & M8? E # khostname-show or set the system's host name "A1 M & C $ K2 A1 w'j
Show Host Name:-G $ J0 U5 c) K3 | 0 q (o
# Hostname
% L # Q5 F (w6 F G8 xlinmu100
: C5 U "q0 ^ 0 G3 I! '0 R' {the host name of this host is linmu100, and the Host Name of the current host is displayed without parameters; 9 K2 x * F & Z; J3 v o8 V9 Z
Temporary Host Name: 0 L-E8 e "S. | 2 P0 F
# Hostname test100
'A1 s d k: Z. Y1 y # hostname note: the host name is displayed.
* R6 P1 d % A9 P % v % V5 Q8 B: ftest100;} * G' P/R/M8 Y: _ 0 x * H1} 0 B-y ({
Using the hostname tool to set the host name is only temporary. This host will not exist the next time you restart the system; + S: H8 _ 0 e "F $? 5 g'r
Display Host IP Address:
9 d: X (v, N "X8 [; C # hostname-I
4 J6 @ # X "y' Q7 C5 l192.168.1.100

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.