A brief analysis of Linux resolv.conf

A brief analysis of Linux resolv.conf

1. Introduction

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

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

2. Configuration details

The configuration of resolv.conf mainly includes the following items:
(1) nameserver xxxx. Used to configure the DNS server. You can use multiple nameservers to specify multiple DNS servers.
(2) Search domain1 domain2 baidu.com. This option can be used to specify multiple domain names, separated by spaces or tabs. Its function is that when the accessed domain name cannot be resolved by DNS, the resolver will add the parameters specified by search to the domain name and re-request DNS until it is correctly resolved or the list of domain names specified by search is exhausted. 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 the local domain name. If search is not set, search defaults to the value of domain.
(4) sortlist IP/netmask IP. Allows to sort the domain results in a specific order. Its parameters are an IP or a mask-IP pair, the mask is optional, separated by a slash. for example:

sortlist 130.155.160.0/255.255.240.0 130.155.0.0

(5) options. Built-in variables used to configure the resolver, not commonly found in resolv.conf. The syntax format is as follows:

options [option] ...

The value of option is as follows:

ndots:[n]: Sets the minimum number of dots that a domain name must contain when calling res_query() to resolve the domain name
timeout:[n]: Set the timeout for waiting for the DNS server to return, in seconds. The default value is RES_TIMEOUT=5, see <resolv.h>
attempts:[n]: Sets the number of times the resolver initiates domain name resolution requests to the DNS server. The default value is RES_DFLRETRY=2, see <resolv.h>
rotate: Set RES_ROTATE in _res.options to access nameserver in round-robin mode to achieve load balancing
no-check-names: Set RES_NOCHECKNAME in _res.options to disable checking of incoming hostnames and email addresses for invalid characters, such as underscores (_), non-ASCII characters, or control characters.

3. Notes

(1) search and domain cannot coexist. If they exist at the same time, the one that appears last will prevail.
(2) A line starting with a semicolon (;) or a pound sign (#) is a comment line;
(3) Each configuration item must be on a separate line and start with a keyword, with spaces separating configuration values.

4. Examples

Below is the content of 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 a brief analysis of the details of Linux resolv.conf. For more information about Linux resolv.conf, please pay attention to other related articles on 123WORDPRESS.COM!

You may also be interested in:
  • Detailed explanation of the solution to resolv.conf being reset after CentOS restart
  • Solve the problem that modifying the DNS address directly in the /etc/resolv.conf file in Cent0S 6.7 does not take effect after restart

<<:  Native JS to implement image carousel JS to implement small advertising plug-in

>>:  MySQL data duplicate checking and deduplication implementation statements

Recommend

How to use nginx to intercept specified URL requests through regular expressions

nginx server nginx is an excellent web server tha...

Detailed steps for installing, configuring and uninstalling QT5 in Ubuntu 14.04

1. I downloaded QT5.13 version before, but after ...

How to install Maven automatically in Linux continuous integration

Unzip the Maven package tar xf apache-maven-3.5.4...

What is the base tag and what does it do?

The <base> tag specifies the default addres...

Tutorial on installing nginx in Linux environment

Table of contents 1. Install the required environ...

mysql5.7.19 zip detailed installation process and configuration

MySQL v5.7.19 official version (32/64 bit install...

Example code for text origami effect using CSS3

Preface This article mainly shares with you an ex...

Echarts Basic Introduction: General Configuration of Bar Chart and Line Chart

1Basic steps of echarts Four Steps 1 Find the DOM...

An audio-visual Linux distribution that appeals to audiophiles

I recently stumbled upon the Audiovisual Linux Pr...

Teach you how to use webpack to package and compile TypeScript code

TypeScript Bundling webpack integration Usually, ...

Html to achieve dynamic display of color blocks report effect (example code)

Use HTML color blocks to dynamically display data...

Implementation and usage scenarios of JS anti-shake throttling function

Table of contents 1. What is Function Anti-shake?...

Common methods and problems of Docker cleaning

If you use docker for large-scale development but...