DNS address forward resolution

Introduction to DNS

Application of DNS

In daily life, people are used to using domain names to access servers, but machines only recognize IP addresses. There is a many-to-one relationship between domain names and IP addresses. An IP address does not necessarily correspond to only one domain name, and a domain name can only correspond to one IP address. The conversion between them is called domain name resolution. Domain name resolution needs to be completed by a special domain name resolution server, and the whole process is automatic.

Definition of DNS

DNS is the English abbreviation of "domain name system". As a distributed database that maps domain names and IP addresses to each other, it can make it easier for people to access the Internet.
NDS service uses TCP and UDP port 53. TCP port 53 is used to connect to DNS server and UDP port 53 is used to resolve DNS.
The length of each level of domain name is limited to 63 characters, and the total length of the domain name cannot exceed 253 characters.

Domain name structure

http://www.sina.com.cn./
http: / / hostname Secondary domain Top level domain root domain/

The top layer of the tree structure is called the root domain, with "." It means that the corresponding server is called the root server, and the resolution right of the whole domain name space belongs to the server, but the root server cannot bear a huge load. The "delegation" mechanism is adopted to set up some top-level domains under the root domain, and then delegate the resolution right of different top-level domains to the corresponding top-level domain servers respectively, such as assigning the resolution right of COM domain to COM domain server, In the future, any domain name resolution request ending in com will be forwarded to the COM domain server. Similarly, in order to reduce the pressure of the top-level domain, several secondary domains are set up, and the secondary domain is set up with three-level domains or hosts.

Root domain
It is located at the top of the domain name space, usually with a "." express

Top level domain
It generally represents a type of organization or country,
Such as Net (network provider) Com (industrial and commercial enterprises) Org (group organization) Edu (educational institution) Gov (government department) CN (Chinese national domain name)

Secondary domain
It is used to indicate a specific organization in the top-level domain. The secondary domain name under the national top-level domain is uniformly managed by the national network department,
Such as Cn secondary domain name set under the top-level domain name: com.cn,. net.cn,. edu.cn

Subdomain
The domains at all levels created under the secondary domain are collectively referred to as sub domains. Each organization or user can freely apply for registration of their own domain name

host
The host is located at the bottom of the domain name space, which is a specific computer,
If WWW and mail are specific computer names, you can use www.sina.com com. cn., mail.sina.com.cn. This representation is called FQDN (fully qualified domain name), which is also the full name of the host in the domain name

DNS domain name resolution method

Forward resolution: find the corresponding IP address according to the domain name
Reverse resolution: find the corresponding domain name according to the IP address

DNS server type

(1) Main domain name server: responsible for maintaining all domain name information in a region. It is the authoritative information source of all specific information, and the data can be modified. When building the master domain name server, you need to establish the address data file of the responsible area.

(2) Slave domain name server: when the master domain name server fails, shuts down or is overloaded, the slave domain name server provides domain name resolution services as a backup service. The resolution results provided from the domain name server are not determined by themselves, but from the main domain name server. When building a slave domain name server, you need to specify the location of the master domain name server so that the server can automatically synchronize the address database of the region.

(3) Caching domain name server: it only provides the caching function of domain name resolution results, which aims to improve the query speed and efficiency, but there is no domain name database. It obtains the result of each domain name server query from a remote server and puts it in the cache. It will respond to the same information in the future. The cached domain name server is not an authoritative server because all the information provided is indirect information. When building a cached domain name server, you must set the root domain or specify another DNS server as the resolution source.

(4) Forwarding domain name server: responsible for local query of all non local domain names. After receiving the query request, the forwarding domain name server will find it in its cache. If it cannot find it, it will forward the request to the specified domain name server in turn until the search result is found. Otherwise, it will return the unmapped result.

Steps to build DNS domain name resolution server

Install bind package

yum install -y bind

Configure forward resolution

First check the path of the configuration file to be modified

rpm -qc bind   					#Query the path of bind software configuration file
/etc/named.conf					#Master profile
/etc/named.rfc1912.zones		#Zone profile
/var/named/named.localhost		#Area data profile

Modify master profile

vim /etc/named.conf
options {
    listen-on port 53 { 192.168.232.3; };	#Listen to port 53. The IP address uses the local IP that provides the service, or any can be used to represent all
    #listen-on-v6 port 53 { ::1; };			#ipv6 lines can be commented out or deleted if they are not used
    directory       "/var/named";			#Default storage location of area data files
    dump-file       "/var/named/data/cache_dump.db";	#Location of domain name cache database file
    statistics-file "/var/named/data/named_stats.txt";	#Status statistics of files
    memstatistics-file "/var/named/data/named_mem_stats.txt";	#Location of memory statistics file
    allow-query     { any; }; ●Permission to use this DNS The network segment of the resolution service is also available any On behalf of all
	......
}
	
zone "." IN {						#Forward parsing "." Root region
        type hint;					#Type is root area
        file "named.ca";			#The area data file is named Ca, which records the domain name and IP address of 13 root domain servers
};

include "/etc/named.rfc1912.zones";		#Contains all the configurations in the area configuration file

Modify the regional configuration file and add the forward regional configuration

vim /etc/named.rfc1912.zone			#There can be templates in the file, which can be modified after copying and pasting
zone "zzz.com" IN {				●Forward analysis“ benet.com"region
        type master;				#Type main area
        file "zzz.com.zone";		●The specified area data file is benet.com.zone
        allow-update { none; };
};

Configure forward area data file

cd /var/named/
cp -p named.localhost zzz.com.zone	#Keep the permission of the source file and the copy attribute of the owner
vim /var/named/zzz.com.zone
$TTL 1D														#Set the effective time for caching parsing results
@       IN SOA  zzz.com. admin.zzz.com. (
                                        0       ; serial
                                        1D      ; refresh
                                        1H      ; retry
                                        1W      ; expire
                                        3H )    ; minimum
        NS      zzz.com.									#Records the name of the DNS server for the current zone
		A		192.168.232.3								#Record host IP address
www IN	A       192.168.232.20								#Record forward analysis www.benet.com Com corresponding IP
mail IN   A   192.168.232.30
ftp	IN	CNAME	www											#CNAME uses an alias, and ftp is the alias of www
*	IN	A		192.168.80.40								#Pan domain name resolution, "*" represents any host name
						
#"@" here is a variable, the domain name of the current DNS zone
#SOA tag is used to synchronize the area data of master and slave servers. If the update serial number is the same, it will not be updated
#“zzz.com.” This is a fully qualified domain name (FQDN), followed by "." You can't miss it
#“admin.zzz.com.” Indicates the administrator mailbox. Here "@" is a variable, so ".." is used express



Add the DNS server address in the domain name resolution configuration file of the client

vi /etc/resolv.conf			#The modification will take effect immediately
nameserver 192.168.232.3
 or
vi /etc/sysconfig/network-scripts/ifcfg-ens33		#The network card needs to be restarted after modification
DNS1=192.168.232.3

systemctl restart network

Start the service and turn off the firewall

systemctl start named
systemctl stop firewalld
setenforce 0	
#If the service fails to start, you can check the log file to troubleshoot the error
tail -f /var/log/messages
#If the service starts stuck, you can execute the following command to solve it
rndc-confgen -r /dev/urandom -a

Test DNS resolution

nslookup www.benet.com

Tags: Linux network shell

Posted by shab620 on Sun, 17 Apr 2022 00:23:33 +0930