架构师成长之路6.5 DNS服务器搭建(添加记录、负载均衡、DNS视图)

点击返回架构师成长之路

架构师成长之路6.5 DNS服务器搭建(添加记录、负载均衡、DNS视图)

 部署主DNS : 点击
 部署从DNS : 点击

1.添加A记录、CNAME记录、MX记录、PTR记录

1.1 添加A记录

编辑主DNS : /var/named/chroot/etc/carlos.com.zone,在文件末尾添加一条记录

\$ORIGIN .
\$TTL 3600 ; 1 hour
carlos.com IN SOA op.Carlos.com. dns.carlos.com. (
2003 ; serial
900 ; refresh (15 minutes)
600 ; retry (10 minutes)
86400 ; expire (1 day)
3600 ; minimum (1 hour)#TTL
)
NS op.carlos.com.
\$ORIGIN carlos.com.
shanks A 1.2.3.4
op A 1.2.3.4
a A 192.168.122.100  

注意:

  • 将serial值+1 , 从DNS才能主动同步
  • 执行rndc reload命令
  • 分别对主从DNS解析下:host a.carlos.com 127.0.0.1结果应该是192.168.122.100

1.2.添加CNAME记录

编辑主DNS : /var/named/chroot/etc/carlos.com.zone,在文件末尾添加一条记录

\$ORIGIN .
\$TTL 3600 ; 1 hour
carlos.com IN SOA op.Carlos.com. dns.carlos.com. (
2004 ; serial
900 ; refresh (15 minutes)
600 ; retry (10 minutes)
86400 ; expire (1 day)
3600 ; minimum (1 hour)#TTL
)
NS op.carlos.com.
\$ORIGIN carlos.com.
shanks A 1.2.3.4
op A 1.2.3.4
a A 192.168.122.100
cname CNAME a.carlos.com.   

注意:

  • 将serial值+1 , 从DNS才能主动同步
  • 执行rndc reload命令
  • 分别对主从DNS解析下:host cname.carlos.com 127.0.0.1结果应该是192.168.122.100

1.3.添加MX记录

编辑主DNS :/var/named/chroot/etc/carlos.com.zone,在文件末尾添加一条记录

\$ORIGIN .
\$TTL 3600 ; 1 hour
carlos.com IN SOA op.Carlos.com. dns.carlos.com. (
2005 ; serial
900 ; refresh (15 minutes)
600 ; retry (10 minutes)
86400 ; expire (1 day)
3600 ; minimum (1 hour)#TTL
)
NS op.carlos.com.
\$ORIGIN carlos.com.
shanks A 1.2.3.4
op A 1.2.3.4
a A 192.168.122.100
cname CNAME a.carlos.com. 
MX MX 5 1 92.168.122.101

  注意:

  • 将serial值+1 , 从DNS才能主动同步
  • 执行rndc reload命令
  • 分别对主从DNS解析下:host mx.carlos.com 127.0.0.1结果应该是192.168.122.100

1.4.添加PTR记录

编辑主DNS :/var/named/chroot/etc/view.conf,加入ptr的zone配置

zone "168.192.in-addr.arpa" {
type master;
file "168.192.zone";
allow-transfer {
10.6.0.254;
};
notify yes;
also-notify {
10.6.0.254;
};
}; 

编辑主DNS :/var/named/chroot/etc/168.192.zone

$TTL 3600       ; 1 hour
@ IN SOA op.carlos.com. dns.carlos.com. (
2006 ; serial
900 ; refresh (15 minutes)
600 ; retry (10 minutes)
86400 ; expire (1 day)
3600 ; minimum (1 hour)
)
NS op.carlos.com.
102.122 IN PTR a.carlos.com.

 修改168.192.zone文件的属性

chown named.named 168.192.zone
rndc reload

 编辑从DNS:/var/named/chroot/etc/view.conf,加入ptr的zone配置

zone "168.192.in-addr.arpa" {
type slave;
masters {10.5.35.14; };
file "slave.168.192.zone";
};

 从DNS执行rndc reload命令。

分别对两台机器做ptr记录的解析   host 192.168.122.102 127.0.0.1     结果应为a.carlos.com  。

2.  通过DNS实现服务的负载均衡

编辑主DNS:/var/named/chroot/etc/carlos.com.zone,在文件末尾添加一条记录

\$ORIGIN .
\$TTL 3600 ; 1 hour
carlos.com IN SOA op.Carlos.com. dns.carlos.com. (
2007 ; serial
900 ; refresh (15 minutes)
600 ; retry (10 minutes)
86400 ; expire (1 day)
3600 ; minimum (1 hour)#TTL
)
NS op.carlos.com.
\$ORIGIN carlos.com.
shanks A 1.2.3.4
op A 1.2.3.4
a A 192.168.122.100
cname CNAME a.carlos.com. 
MX MX 5 192.168.122.101
a A 192.168.122.101

  注意:

  • 将serial值+1 , 从DNS才能主动同步
  • 执行rndc reload命令
  • 分别对主、从DNS解析下:host a.carlos.com 127.0.0.1结果应该是192.168.122.100和192.168.122.101

3.  配置DNS视图(智能DNS)

配置主DNS: /var/named/chroot/etc/named.conf,在include上面添加

acl group1 {
10.5.35.14;
}; acl group2 {
10.5.35.15;
}; 

配置主DNS: /var/named/chroot/etc/view.conf

view "GROUP1" {
match-clients { group1; };
zone "viewcarlos.com" {
type master;
file "group1.viewcarlos.com.zone";
};
}; view "GROUP2" {
match-clients { group2; };
zone "viewcarlos.com" {
type master;
file "group2.viewcarlos.com.zone";
};
};

配置主DNS:  /var/named/chroot/etc/group1.viewcarlos.com.zone

$ORIGIN .
$TTL 3600 ; 1 hour
viewcarlos.com IN SOA op.viewcarlos.com. dns.viewcarlos.com. (
2008 ; serial
900 ; refresh (15 minutes)
600 ; retry (10 minutes)
86400 ; expire (1 day)
3600 ; minimum (1 hour)
)
NS op.viewcarlos.com.
$ORIGIN viewcarlos.com.
op A 192.168.122.1
view A 192.168.122.1

修改文件所属,加载配置。

chown named.named /var/named/chroot/etc/group*.zone
rndc reload

分别在主机A与B上做view.viewcarlos.com的域名解析测试,结果应为主机A上是192.168.122.1,主机B上是192.168.122.2

....

上一篇:架构师成长之路7.1 CDN理论


下一篇:架构师成长之路6.4 DNS服务器搭建(部署主从DNS)