Analysis of Linux resolv. conf

  • 2021-08-28 21:45:52
  • OfStack

1. Introduction

resolv. conf is the configuration file for the Domain Name System Resolver (DNS Resolver) for various operating systems. Whenever a program needs to access other hosts on Internet through domain name, it needs to use Resolver library function to convert domain name into corresponding IP before it can be accessed.

Note that the Domain Name System Resolver (DNS Resolver) is not an executable program, but a series of library functions of C language, which is used to resolve resolv. conf to obtain IP corresponding to domain name. For the explanation of Resolver, you can use man 3 resolver Check the help manual.

2. Configuration details

The configuration of resolv. conf mainly includes the following items:
(1) nameserver x. x. x. x. To configure an DNS server, you can specify multiple DNS servers using multiple nameserver.
(2) search domain1 domain2 baidu. com. This option can be used to specify multiple domain names, separated by spaces or tab keys. Its function is that when the accessed domain name cannot be resolved by DNS, resolver will add the parameters specified by search to the domain name and re-request DNS until it is correctly resolved or the domain name list specified by search is tried. For example:


#ping news
PING news.baidu.com (74.125.128.101) 56(84) bytes of data.
64 bytes from hg-in-f101.1e100.net (74.125.128.101): icmp_req=1 ttl=47 time=78.9 ms
64 bytes from hg-in-f101.1e100.net (74.125.128.101): icmp_req=2 ttl=47 time=63.6 ms

(3) domain mydomain. com. Used to define local domain names. When search is not set, search defaults to the value of domain.
(4) sortlist IP/netmask IP. Allows you to sort the resulting domain name results in a specific way. Its parameters are IP or the mask-IP pair, and the masks are optional and separated by slashes. For example:


sortlist 130.155.160.0/255.255.240.0 130.155.0.0

(5) options. Built-in variables used to configure resolver are not common configurations for resolv. conf. The syntax format is as follows:


options [option] ...

The values for the option section are as follows:

ndots: [n]: Sets the minimum number of points a domain name contains when calling res_query () to resolve a domain name
timeout: [n]: Sets the timeout, in seconds, to wait for the dns server to return. Default value RES_TIMEOUT=5, see < resolv.h >
attempts: [n]: Sets the number of requests that resolver initiates domain name resolution to the DNS server. The default value is RES_DFLRETRY=2, see < resolv.h >
rotate: RES_ROTATE is set in _ res. options, and nameserver is accessed by polling mode to realize load balancing
no-check-names: Set RES_NOCHECKNAME in _ res. options to disable checking for incoming host names and mail addresses for invalid characters, such as underscores (_), non-ASCII characters, or control characters

3. Considerations

(1) search and domain cannot coexist. If they coexist, the last one shall prevail.
(2) Semicolon (; ) or behavior comment lines beginning with a pound sign (#);
(3) Every 1 configuration item must be in a separate row, which starts with keywords and separates configuration values with spaces.

4. Examples

The following is the contents of an resolv. conf.


nameserver 202.102.192.68
nameserver 202.102.192.69
search qq.com baidu.com
options no-check-names
options attempts:1
options timeout:1

The above is the detailed content of Linux resolv. conf. For more information about Linux resolv. conf, please pay attention to other related articles on this site!


Related articles: