1.dns安装及启用
服务端(192.168.0.117):
dnf install bind -y
firewall-cmd --permanent --add-service=dns
firewall-cmd --reload
systemctl restart named.service
2.高速缓存dns
vim /etc/named.conf
11 listen-on port 53 { any; };
19 allow-query { any; };
20 forwarders { 114.114.114.114; };
35 dnssec-validation no;
ip route add default via 192.168.0.101
客户端1:
vim /etc/resolv.conf
nameserver 192.168.0.117
dig www.qq.com
客户端2:
vim /etc/resolv.conf
nameserver 192.168.0.117
dig www.qq.com
3.正向解析
vim /etc/named.conf
#forwarders { 114.114.114.114; };
vim /etc/named.rfc1912.zones
zone "westos.org" IN {
type master;
file "westos.org.zone";
allow-update { none; };
};
cp -p named.localhost westos.org.zone
vim /var/named/westos.org.zone
$TTL 1D
@ IN SOA dns.westos.org. westos.westos.org. (
0 ; serial
1D ; refresh
1H ; retry
1W ; expire
3H ) ; minimum
NS dns.westos.org.
dns A 192.168.0.117
www A 192.168.0.217
systemctl restart named.service
测试:
客户端:
vim /etc/resolv.conf
nameserver 192.168.0.117
4.反向解析
服务端:
vim /var/named/westos.org.zone
$TTL 1D
@ IN SOA dns.westos.org. westos.westos.org. (
0 ; serial
1D ; refresh
1H ; retry
1W ; expire
3H ) ; minimum
NS dns.westos.org.
dns A 192.168.0.117
www A 192.168.0.217
bbs CNAME test.westos.org.
test A 192.168.0.166
test A 192.168.0.188
systemctl restart named
客户端:
5.邮件解析
服务端:
vim /var/named/westos.org.zone
westos.org. MX 1 192.168.0.117.
systemctl restart named
客户端:
dnf install postfix mailx -y
systemctl start postfix.service
dig -t mx westos.org
mail root@westos.org
6.双向解析
配置一台双网卡主机
192.168.0.117
1.1.1.117
两台不同的单网卡主机
192.168.0.101
1.1.1.217
双网卡主机:
cd /var/named/
cp -p westos.org.zone westos.org.zone.inter
cp -p /etc/named.rfc1912.zones /etc/named.rfc1912.inter.zones
vim /etc/named.conf
/*
zone "." IN {
type hint;
file "named.ca";
};
include "/etc/named.rfc1912.zones";
include "/etc/named.root.key";
*/
view localnet {
match-clients { 192.168.0.0/24; };
zone "." IN {
type hint;
file "named.ca";
};
include "/etc/named.rfc1912.zones";
};
view internet {
match-clients { any; };
zone "." IN {
type hint;
file "named.ca";
};
include "/etc/named.rfc1912.inter.zones";
};
include "/etc/named.root.key";
vim /etc/named.rfc1912.inter.zones
31 file “westos.org.zone.inter”;
vim westos.org.zone.inter
$TTL 1D
@ IN SOA dns.westos.org. westos.westos.org. (
0 ; serial
1D ; refresh
1H ; retry
1W ; expire
3H ) ; minimum
NS dns.westos.org.
dns A 1.1.1.117
www A 1.1.1.217
bbs CNAME test.westos.org.
test A 1.1.1.166
test A 1.1.1.188
westos.org. MX 1 1.1.1.117.
systemctl restart named
客户端测试:
在1.1.1.217解析
vim /etc/resolv.conf
nameserver 1.1.1.117
dig www.westos.org
在192.168.0.101解析
vim /etc/resolv.conf
nameserver 192.168.0.117
dig www.westos.org
7.辅助dns
在辅助dns主机设置:
dnf install bind -y
systemctl enable --now named.service
vim /etc/named.conf
vim /etc/named.rfc1912.zones #29行
zone "westos.org" IN {
type slave;
masters { 192.168.0.117; };
file "slaves/westos.org.zone";
};
systemctl restart named.service
主dns:
vim /etc/named.rfc1912.zones #33行
also-notify { 192.168.0.217; };
vim /var/named/westos.org.zone
1 ; serial
www A 192.168.0.222
systemctl restart named.service
测试:
辅助dns
vim /etc/resolv.conf
nameserver 192.168.0.217
dig www.westos.org
8.dns的更新方式
192.168.0.117主机:
搭建dhcp服务:
dnf install dhcp-server -y
cp /usr/share/doc/dhcp-server/dhcpd.conf.example /etc/dhcp/dhcpd.conf
vim /etc/dhcp/dhcpd.conf
systemctl restart dhcpd
设置客户端:
117服务端:
vim /var/named/westos.org.zone
node2 A 192.168.0.240
systemctl restart named
客户端测试:
dig node2.westos.org
如果更改117主机dhcp配置文件分配ip的范围,取消240,dhcp客户端解析到的ip还是240,该如何解决
基于ip的更新
vim /etc/named.rfc1912.zones
allow-update { 192.168.0.101; };
systemctl restart named
测试:
101服务端:
nsupdate -k /mnt/Kwestos.+163+02157.
> server 192.168.0.117
> update add linux.westos.org 86400 A 192.168.0.199
> send
客户端:
101服务端:
nsupdate -k /mnt/Kwestos.+163+02157.
> update del linux.westos.org
> send
客户端:
基于key的更新
192.168.0.117主机:
cd /mnt
dnssec-keygen -a HMAC-SHA256 -b 128 -n HOST westos
cp /etc/rndc.key /etc/westos.key -p
vim /etc/westos.key
key "westos" {
algorithm hmac-sha256;
secret "PP6PFqmgGKqPkghitwslag==";
};
vim /etc/named.conf
include “/etc/westos.key”;
vim /etc/named.rfc1912.zones
allow-update { key westos; };
systemctl restart named
测试:
117服务端:
nsupdate -k /mnt/Kwestos.+163+02157.
> server 192.168.0.117
> update add linux.westos.org 86400 A 192.168.0.199
> send
客户端:
117服务端:
nsupdate -k /mnt/Kwestos.+163+02157.
> update del linux.westos.org
> send
客户端:
9.ddns(dns+dhcp)
117服务端:
cd /var/named/
ls
rm -rf westos.org.zone.jnl
vim westos.org.zone
删除node2 A 192.168.0.240
systemctl restart named
vim /etc/dhcp/dhcpd.conf
14 ddns-update-style interim;
key westos {
algorithm hmac-sha256;
secret "PP6PFqmgGKqPkghitwslag==";
};
zone westos.org. {
primary 192.168.0.117;
key westos;
}
systemctl restart dhcpd
dhcp客户端:
测试:
dhcp和dns主机改变dhcp服务ip分配范围
systemctl restart dhcpd
dhcp客户端node2:
网卡工作方式为dhcp
nmcli connection down ens3
nmcli connection up ens3
ifconfig
dig node2.westos.org