Brief description: DNS (Domain Name System) domain name system maps the website domain name and IP address, and the user can query the specific IP address of the website and obtain the website content by entering the website domain name.
The role of the DNS server:
1. Resolve domain name to IP address
2. The client sends a domain name query request to the DNS server (the DNS server has its own IP address)
3. The DNS server informs the client of the IP address of the Web server
4. The client communicates with the Web server
Example: Assume that there are three hosts in the domain "alex.com" where a company is located, and the host names of the three hosts are ayc.alex.com, byc.alex.com, and cyc.byc.com. The IP address of the DNS server is: 192.168.1.3. The IP addresses of the three hosts are:
192.168.1.4,192.168.1.5,192.168.1.6
The DNS server is required to be able to resolve the correspondence between the three host names and IP addresses.
1. First install the bind package
The first method to install:
Key combination: ctrl+f
The second method:
Create a mount point temp under /mnt
Go to /etc/yum.repos.d and create a file at the end of the repo
configuration file
Temporarily mount the disk to the temp file just created under /mnt
View all available files
yum install -y bind-* (install DNS service)
2. Network configuration
vim /etc/sysconfig/network-scripts/ifcfg-ens33
systemctl restart network (restart network)
Check whether the IP address configuration is successful
3. Configure the hostname
nmtui enters the graphical configuration page
4.vim /etc/named.conf (main configuration file)
After configuring this part, move to the bottom
Add the command at the bottom
zone "alex.com" IN{
type master;
file "up.zone";
};
zone "1.168.192.in-addr.arpa" IN{
type master;
file "down.zone";
};
注释:
//正向解析区域命名格式:域名
// zone "正向解析区域" IN {
// type master;
// file "正向解析的配置文件名";
// allow-update { none; };
// };
//反向解析区域命名格式:网段倒过来+.in-addr.arpa
// zone "反向解析区域" IN {
// type master;
// file "反向解析的配置文件名";
// allow-update { none; };
// };
After exiting, use this command to check the configuration file just now for errors. (If there is no problem, nothing will be displayed)
named-checkconf /etc/named.conf
First enter the directory below
5. Configure the forward parsing file
cp named.localhost up.zone -p //复制正向解析文件模板
vim up.zone //配置文件
$TTL 1D
@ IN SOA alex.com. root.alex.com. (
0 ; serial
1D ; refresh
1H ; retry
1W ; expire
3H ) ; minimum
NS dns.alex.com.
dns A 192.168.1.3
ayc A 192.168.1.4
byc A 192.168.1.5
cyc A 192.168.1.6
判断正向解析文件:
[root@localhost named]# named-checkzone up.zone /var/named/up.zone
zone up.zone/IN: loaded serial 0
OK
6. Configure reverse parsing file
[root@localhost named]# cp up.zone down.zone -p //复制反向解析文件模板
[root@localhost named]# vim down.zone //配置反向解析文件模板
$TTL 1D
@ IN SOA alex.com. root.alex.com. (
0 ; serial
1D ; refresh
1H ; retry
1W ; expire
3H ) ; minimum
NS dns.alex.com.
3 PTR dns.alex.com.
4 PTR ayc.alex.com.
5 PTR byc.alex.com.
6 PTR cyc.alex.com.
~
判断反向解析文件:
t@localhost named]# named-checkzone down.zone /var/named/down.zone
zone down.zone/IN: loaded serial 0
OK
7. Test whether the DNS server is set up successfully
重启named服务:
root@localhost named]# systemctl restart named
[root@localhost named]# nslookup
> 192.168.1.4
Server: 192.168.1.3
Address: 192.168.1.3#53
4.1.168.192.in-addr.arpa name = ayc.alex.com.
> cyc.alex.com
Server: 192.168.1.3
Address: 192.168.1.3#53
Name: cyc.alex.com
Address: 192.168.1.6
>