Linux企业级(6)——Linux企业DNS服务器搭建
dns的名词解释
dns:
domain name service(域名解析服务)
/etc/resolv.conf
nameserver 172.25.254.33
host www.baidu.com
dig www.baidu.com
A记录
SOA
dns顶级
. 13
次级
.com .net .edu .org ....
baidu.com
bind
named
/etc/named.conf
/var/named
端口
关于报错信息:
1.no servers could be reached
2.服务启动失败
3.dig 查询状态
NOERROR
REFUSED
SERVFAIL
NXDOMAIN
二.dns服务的安装与启用 : 在服务器中 :
dnf install bind.x86_64 -y
systemctl enable --now named
netstat -antlupe | grep named
systemctl start firewalld
firewall-cmd --permanent --add-servive=dns
firewall-cmd --reload
vim /etc/resolv.conf
nameserver 114.114.114.114
vim /etc/sysconfig/network
GATEWAY=172.25.254.32
在客户端中:
vim /etc/resolv.conf
nameserver 172.25.254.233
服务器中:
vim /etc/named.conf
将11,19改成 listen-on port 53 { any; };
allow-query { any; };
dnssec-validation no ;
systemctl restart named
测试:在客户端中 dig www.baidu.com
三.高速缓存dns : 服务器中:
vim /etc/named.conf
20行加 :forwarders { 114.114.114.114; } ;
然后在另外两台客户端中,
vim /etc/resolv.conf
写 nameserver 主机器ip,设可以上网的网关
然后分别dig相同的网站看访问时间的差别
tips:火墙允许dns
四:dns的正向解析 : 在服务器中:
vim /etc/resolv.conf
vim /etc/named.conf
vim /etc/named.rfc1912.zone
zone "westos.org" IN {
type master;
file "westos.org.zone";
allow-update { none; };
};
cd /var/named
ls
cp -p named.localhost westos.org.zone
ll
vim /var/named/westos.org.zone
$TTL 1D
@ IN SOA dns.westos.org. root.westos.org. (
0 ; serial
1D ; refresh
1H ; retry
1W ; expire
3H ) ; minimum
NS dns.westos.org.
dns A 172.25.254.233
www A 172.25.254.111
然后在客户端中进行测试:
五.dns的反向解析 : 服务器中:
vim /etc/named.rfc1912.zones
zone "254.25.172.in-addr.arpa" IN {
type master;
file "172.25.254.ptr";
allow-update { none; };
};
cd /var/named/
cp -p named.loopback 172.25.254.ptr
vim 172.25.254.ptr
systemctl restart named
测试:
dig -x 172.25.254.233
六.dns的双向解析 实验环境:
客户端两台 1.1.1.0网段 ##ifconfig ens3 1.1.1.133 172.25.254.0网段 ##ifconfig ens3 172.25.254.133
服务端一台两个网段的ip
1.1.1.33
172.25.254.233
在1.1.1.0网段的客户机中(1.1.1.133) nameserver 1.1.1.233 在172.25.254.0网段的客户机中(172.25.254.133 nameserver 172.25.254.233
cd /var/named/
cp -p westos.org.zone westos.org.inter
vim westos.org.inter
cp -p /etc/named.rfc1912.zones /etc/named.rfc1912.inters
vim /etc/named.rfc1912.inters
zone "westos.com" IN {
type master;
file "westos.org.inter";
allow-update { none; };
};
vim /etc/named.conf
view localnet {
match-clients { 1.1.1.0/24; };
zone "." IN {
type hint;
file "named.ca";
};
include "/etc/named.rfc1912.inters";
};
view any {
match-clients { any; };
zone "." IN {
type hint;
file "named.ca";
};
include "/etc/named.rfc1912.zones";
};
systemctl restart named
测试:分别在两台客户端dig同一个地址,显示不同的ip解析
七.DNS的集群 :
vim /var/named/westos.org.zone
$TTL 1D
@ IN SOA dns.westos.org. root.westos.org. (
2021080603 ; serial
1D ; refresh
1H ; retry
1W ; expire
3H ) ; minimum
NS dns.westos.org.
dns A 172.25.254.233
www CNAME lee.a
lee.a A 172.25.254.133
lee.a A 172.25.254.233
westos.org MX 1 172.25.254.233.
vim /etc/named.rfc1912.zones
zone "westos.com" IN {
type master;
file "westos.com.zone";
allow-update { none; };
also-notify { 172.25.254.133; };
};
dnf install bind -y
systemctl disable --now firewalld
vim /etc/named.conf
vim /etc/named.rfc1912.zones
zone "westos.org" IN {
type slave;
masters {172.25.254.223;};
file "slaves/westos.org.zone";
};
ls /var/named -l 看slaves 是不是属于named
systemctl restart named
测试:在dns主机上更改数据文件,并增加serial序列号,重启named
辅助DNS机上看到信息已与主机同步。
八.DNS的更新 在服务器中:
dnf install dhcp-server -y
cp /usr/share/doc/dhcp-server/dhcpd.conf.example /etc/dhcp/dhcpd.conf
vim /etc/dhcp/dhcpd.conf
rpm -qc bind
dnssec-keygen -a HMAC-SHA256 -b 128 -n HOST westoskey ##生成秘钥
mv Kwestoskey.+163+63449.private Kwestoskey.+163+63449.key /mnt ##将两把钥匙移动到mnt目录
cd /mnt ls
cat Kwestoskey.+163+63449.private cat Kwestoskey.+163+63449.key
vim /etc/westos.key
key "westoskey" {
algorithm hmac-sha256;
secret "8SxQ/8DZM6zyaYQx4vth7Q=="; ##改写成为自己生成的密钥
};
vim /etc/named.conf
写一句 include"/etc/westos.key";
vim /etc/named.rfc1912.zones
vim /etc/dhcp/dhcpd.conf
systemctl restart dhcpd
systemctl restart named
测试 :客户端中,设置客户端网络为dhcp,保证ip可以从dhcp服务中获取。更改客户端主机名为westosb.westos.com dig westosb.westos.com
1.查看/etc/resolv.conf内容,没有nameserver
2.重启网卡获取ip。查看/etc/resolv.conf内容,nameserver为服务器ip,说明获取成功,ip为172.25.254.71.
3.主机名为westosb.westos.org 属于westos.org这个域
4.dig westosb.westos.org
|