Linux under Hosts, host.conf, resolv.conf

Source: Internet
Author: User
Tags domain name server nameserver

/etc/resolv.conf

The file is a configuration file for DNS domain name resolution, and its format is simple, with each line beginning with a keyword followed by configuration parameters.
There are four key words in resolv.conf, namely:
nameserver #定义DNS服务器的IP地址
Domain #定义本地域名
Search #定义域名的搜索列表
sortlist #对返回的域名进行排序
Detailed Description:
nameserver indicates the IP address of the DNS server. There can be many lines of nameserver, each with an IP address. At query time, the order of nameserver in this file is performed, and the following nameserver is queried only if the first nameserver is unresponsive.
Domain declares the name of the host. Many programs use it, such as a mail system, and are used when DNS queries are made for hosts that do not have a domain name. If there is no domain name, the hostname is used, removing all at the first point (.) The previous content.
search its multiple parameters indicate the order of the domain name query. When you want to query a host that does not have a domain name, the host is found separately in the domain that is declared by search. Domain and search cannot coexist, and if they exist at the same time, subsequent occurrences will be used.
Sortlist allows a specific sort of domain results to be obtained. Its parameters are network/mask pairs that allow arbitrary order of arrangement.

An example of/etc/resolv.conf:
Domain centoscn.com
Search www.centocn.com www.wgjlb.com
nameserver 202.96.128.86
nameserver 202.96.128.166
The most important is the nameserver keyword, if you do not specify nameserver can not find the DNS server, other keywords are optional. The default/etc/resolv.conf file is not available in Red hat, and its content is created dynamically based on the options given at the time of installation.
=====================================================

/etc/hosts

/etc/hosts file configuration method under Linux operating system
-----------------------------------------------------
1, about/etc/host, hostname and IP configuration file
hosts-the static table lookup for host name (host-Name query-still tables)
Hosts file is a Linux system responsible for the rapid resolution of IP address and domain name files, in ASCII format in the "/etc" directory, the file name "hosts" (different versions of Linux, this configuration file may also be different.) For example, Debian's counterpart file is/etc/hostname). The Hosts file contains mappings between IP addresses and host names, and also includes aliases for host names. In the absence of a domain name server, all network programs on the system can query the file to resolve the IP address corresponding to a host name, otherwise it will need to use the DNS service program to resolve. You can often add common domain names and IP address mappings to the Hosts file for quick and easy access.
2. Configuration Files
This file can be configured with the host IP and the corresponding hostname, which is not negligible for the server type Linux system. On the LAN or the Internet, each host has an IP address that separates each host and can communicate based on IP. But the IP address is not easy to remember, so there is a domain name. In a local area network, each machine has a host name, which is used to differentiate the host and facilitate mutual access.
The relevant configuration file of the Linux hostname is/etc/hosts; This file tells the host which domain names correspond to those IPs, and which IP addresses those host names:
like there's a definition in the file.
assuming 192.168.1.100 is a Web server, entering http://linumu100 or http://test100 on a Web page will open the 192.168.1.100 Web page.
Typically, this file first records the native IP and hostname:</p>
3. Configuration file Format Description
General/etc/hosts content generally has the following similar content:
127.0.0.1 localhost.localdomain localhost
192.168.1.100 linmu100.com linmu100
192.168.1.120 ftpserver ftp120
in general, each behavior of the hosts file is a host, each line consists of three parts, and each part is separated by a space. Where the # starts with a line that is not explained by the system.
the Hosts file has the following format:
IP Address host name/domain name
The first part: network IP address;
Part Two: hostname or domain name;
The third part: hostname alias;
of course, each line can also be two parts, that is, the host IP address and host name, such as 192.168.1.100 linmu100.
Here you can explain the difference between host name (hostname) and domain name: hostname is usually used in LAN, through Hosts file, host name is resolved to corresponding IP, domain name is usually used on the internet, However, if the computer does not want to use the domain name resolution on the Internet, you can change the hosts file to join your own domain name resolution.
4./hosts files can help resolve what problems
4.1 Remote login to Linux host too slow problem
Sometimes the client wants to telnet to a Linux host, but each login password will wait for a long time to enter, this is because the Linux host in the return of information need to resolve IP, if the hosts in the Linux host file in advance to join the client's IP address, Then telnet to Linux from the client will become very fast.
NOTE: Remote login here is not just ssh, it may be MySQL remote login, or file sharing query.
4.2 Dual-Machine interconnect
when the two hosts are only two-computer interconnection, both hosts need to set their own IP, while in the other's Hosts file to add their own IP and host name.
5. Hostname Modification tool hostname
in fact, the hostname of the modification also has a special tool, that is hostname
Hostname-show or set the system ' s host name
Display host Name:
# hostname
linmu100
The host name of this host is linmu100, and no parameter is used to display the host name of the current host;
temporarily set host name:
# hostname test100
# hostname Note: Display host name
test100
using the Hostname tool to set the hostname is only temporary, the next time you restart the system, the host name will not exist;
Show host IP:
# hostname-i
192.168.1.100
 
==========================================================
the difference between hosts, host.conf and resolv.conf under Linux

--------------------------------------------------------
located in the/etc/directory, here to differentiate
1.hosts file.
similar to the file of host under Windows system, it is a text file which contains some correspondence between IP and domain name.
2.host.conf. #解析器查询顺序配置文件
Example: vi/etc/host.conf
The order hosts bind indicates that the local hosts file is queried before attempting to find the BIND DNS server if there are no results.
3. resolv.conf
Configure the configuration file for the Linux system DNS server:
vi/etc/resolv.conf
NameServer 192.168.0.1
NameServer 202.99.96.68
==========================================================
The difference between hosts, host.conf and resolv.conf under Linux
--------------------------------------------------------
Located in the/etc/directory, here to differentiate
1.hosts file.
Similar to the file of host under Windows system, it is a text file which contains some correspondence between IP and domain name.
2.host.conf. #解析器查询顺序配置文件
Example: vi/etc/host.conf
The order hosts bind indicates that the local hosts file is queried before attempting to find the BIND DNS server if there are no results.
3. resolv.conf
Configure the configuration file for the Linux system DNS server:
Vi/etc/resolv.conf
NameServer 192.168.0.1
NameServer 202.99.96.68

Linux under Hosts, host.conf, resolv.conf

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.