Linux centos7下搭建并实现智能DNS

1.修改主配置文件

vim /etc/named.conf   acl

//添加的行 start
acl beijingnet {
	192.168.137.0/24;
	192.168.135.0/24;
};
acl shanghainet {
	192.168.217.0/24;
	192.168.216.0/24;
};
acl othernet {
	any;
};
//添加的行 end

options {
	//listen-on port 53 { 127.0.0.1; };
	listen-on-v6 port 53 { ::1; };
	directory 	"/var/named";
	dump-file 	"/var/named/data/cache_dump.db";
	statistics-file "/var/named/data/named_stats.txt";
	memstatistics-file "/var/named/data/named_mem_stats.txt";
	recursing-file  "/var/named/data/named.recursing";
	secroots-file   "/var/named/data/named.secroots";
	//allow-query     { localhost; };
	allow-transfer	  { none;};
	/* 
	 - If you are building an AUTHORITATIVE DNS server, do NOT enable recursion.
	 - If you are building a RECURSIVE (caching) DNS server, you need to enable 
	   recursion. 
	 - If your recursive DNS server has a public IP address, you MUST enable access 
	   control to limit queries to your legitimate users. Failing to do so will
	   cause your server to become part of large scale DNS amplification 
	   attacks. Implementing BCP38 within your network would greatly
	   reduce such attack surface 
	*/
	recursion yes;

	dnssec-enable no;
	dnssec-validation no;

	/* Path to ISC DLV key */
	bindkeys-file "/etc/named.iscdlv.key";

	managed-keys-directory "/var/named/dynamic";

	pid-file "/run/named/named.pid";
	session-keyfile "/run/named/session.key";
};

logging {
        channel default_debug {
                file "data/named.run";
                severity dynamic;
        };
};

//添加的行 start  view 

view view_beijing {
	match-clients { beijingnet;};
	include "/etc/named.rfc1912.zones.bj";
};

view view_shanghai {
	match-clients { shanghainet;};
	include "/etc/named.rfc1912.zones.sh";
};
view view_other {
	match-clients { othernet;};
	include "/etc/named.rfc1912.zones";
};
//添加的行 end 


include "/etc/named.root.key";



2.编辑添加文件

vim /etc/named.rfc1912.zones.bj

zone "magedu.com" {
    type master;
    file "magedu.com.zone.bj";
};

vim /etc/named.rfc1912.zones.sh
zone "magedu.com" {
    type master;
    file "magedu.com.zone.sh";
};

vim /etc/named.rfc1912.zones
zone "magedu.com" {
    type master;
    file "magedu.com.zone.other";
};

修改其文件权限 
chmod 640 /etc/named.rfc1912.zones.*

加入named 组权限
chgrp named /etc/named.rfc1912.zones.*

3.编辑添加数据文件

vim magedu.com.zones.bj 
$TTL 1D
@ IN SOA ns1 admin ( 1 1H 1H 1D 3H )
	NS ns1
ns1	A 192.168.137.133
www	A 192.168.137.100

vim  magedu.com.zones.sh
$TTl 1D
@ IN SOA ns1 admin ( 1 1H 1H 1D 3H)
	NS ns1
ns1	A  192.168.31.7
www	A  172.16.0.100

vim magedu.com.zones.other
$TTL 1D
@ IN SOA ns1 admin ( 1 1H 1H 1D 3H )
	NS ns1
ns1	A 192.168.37.7
www	A 8.8.8.8

修改文件权限
chmod 640 magedu.com.zones.other.*

chgrp named /var/named/magedu.com.zone.*

4.测试

客户机 192.168.137网段则显示北京的DNS

Linux centos7下搭建并实现智能DNS_第1张图片
客户机 192.168.217网段则显示上海的DNS
Linux centos7下搭建并实现智能DNS_第2张图片

客户机 12730.0.1网段则显示其他DNS
Linux centos7下搭建并实现智能DNS_第3张图片

你可能感兴趣的:(linux,linux)