在实际的网络应用中,我们有时希望对于同一个Domain Name能够根据不同的请求IP

地址/区域,解析到不同的对应IP地址,比如:有时对于企业内部网络和外部网络希望对同一域名解析到不同的IP地址以达到安全目的或者应用目的,又比如为了解决中国南北方电信/网通互访速度差异问题,您也会希望电信用户解析到的域名IP是位于电信网络中的服务器,网通用户亦然,使用户能够访问到临近的最快的服务器。

而这些应用都可以通过对DNS的简单配置达到,使用DNS达到这一目的有以下的优点:

l  低成本-无需添加任何专用设备,只需通过简单配置即可;

l  灵活性强-可随时增加/删除解析规则;

l  有一定的可扩展能力-如果搭配Round Robin DNS可无缝快速的配置简单的负载均衡;

下面,我们借助Bind 9(Bind 8没有这个功能哦)的这一特殊功能来实现域名的分离解析。在此例中,我们继续沿用x.centos.org作为域名,让局域网192.168.0.0/24内的机器除了192.168.0.40外都能解析到192.168.0.38,而192.168.0.40这台机器只能解析到192.169.0.39这个地址。

首先,需要修改named.conf文件,对view “internal”和view “external”这两个视图区域进行分别设置。我们将view “localhost_resolver”这个视图、key ddns key以及view视图内的slave这个区域都注释掉。然后,修改internal和external两个视图。

//

// Sample named.conf BIND DNS server 'named' configuration file

// for the Red Hat BIND distribution.

//

// See the BIND Administrator's Reference Manual (ARM) for details, in:

//   file:///usr/share/doc/bind-*/arm/Bv9ARM.html

// Also see the BIND Configuration GUI : /usr/bin/system-config-bind and

// its manual.

//

options

{

// Those options should be used carefully because they disable port

// randomization

 query-source    port 53;            

// query-source-v6 port 53;

// Put files that named is allowed to write in the data/ directory:

directory "/var/named"; // the default

dump-file                  "data/cache_dump.db";

statistics-file  "data/named_stats.txt";

memstatistics-file  "data/named_mem_stats.txt";

};

logging

{

/*      If you want to enable debugging, eg. using the 'rndc trace' command,

*      named will try to write the 'named.run' file in the $directory (/var/named).

*      By default, SELinux policy does not allow named to modify the /var/named directory,

*      so put the default debug log file in data/ :

*/

channel default_debug {

file "data/named.run";

severity dynamic;

};

};

//

// All BIND 9 zones are in a "view", which allow different zones to be served

// to different types of client addresses, and for options to be set for groups

// of zones.

//

// By default, if named.conf contains no "view" clauses, all zones are in the

// "default" view, which matches all clients.

//

// If named.conf contains any "view" clause, then all zones MUST be in a view;

// so it is recommended to start off using views to avoid having to restructure

// your configuration files in the future.

//

#view "localhost_resolver"     

#{

/* This view sets up named to be a localhost resolver ( caching only nameserver ).

* If all you want is a caching-only nameserver, then you need only define this view:

*/

#       match-clients                   { localhost; };     

#       match-destinations        { localhost; };    

#       recursion yes;                   

         # all views must contain the root hints zone:

#       include "/etc/named.root.hints";

 

        /* these are zones that contain definitions for all the localhost

         * names and addresses, as recommended in RFC1912 - these names should

          * ONLY be served to localhost clients:

          */

#       include "/etc/named.rfc1912.zones";

#};

view "internal"

{

/* This view will contain zones you want to serve only to "internal" clients

that connect via your directly attached LAN interfaces - "localnets" .

*/

match-clients           { 192.168.0.40; };  //设置internal区域由192.168.0.40这个地址解析。

#       match-destinations        { localnets; };

recursion yes;

// all views must contain the root hints zone:

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

 include "/etc/named.rfc1912.zones";  //将internal视图的区域定义文件包含进来。

// you should not serve your rfc1912 names to non-localhost clients.

// These are your "authoritative" internal zones, and would probably

// also be included in the "localhost_resolver" view above :

zone "my.internal.zone" {

type master;

file "my.internal.zone.db";

};

#       zone "my.slave.internal.zone" {            

#                type slave;

#                file "slaves/my.slave.internal.zone.db";

#                masters { /* put master nameserver IPs here */ 127.0.0.1; } ;

                   // put slave zones in the slaves/ directory so named can update them

#       };     

#       zone "my.ddns.internal.zone" {          

#                type master;

#                allow-update { key ddns_key; };

#                file "slaves/my.ddns.internal.zone.db";

                   // put dynamically updateable zones in the slaves/ directory so named can update them

#       };                        

};

#key ddns_key  

#{

#       algorithm hmac-md5;

#       secret "use /usr/sbin/dns-keygen to generate TSIG keys";

#};

view    "external"

{

/* This view will contain zones you want to serve only to "external" clients

* that have addresses that are not on your directly attached LAN interface subnets:

*/

match-clients           { !192.168.0.40;192.168.0.0/24;  }; //设置external视图由192.168.0.0

这个网段的机器解析,但

192.168.0.40这台主机不能解析。

#       match-destinations        { any; };

recursion no;

// you'd probably want to deny recursion to external clients, so you don't

// end up providing free DNS service to all takers

// all views must contain the root hints zone:

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

 include “/etc/named.other.zones”;   //添加external的区域定义文件,文件名随意。

// These are your "authoritative" external zones, and would probably

// contain entries for just your web and mail servers:

zone "my.external.zone" {

type master;

file "my.external.zone.db";

};

};

接下来,修改internal和external视图的区域定义文件。首先,修改internal区域定义文件named.rfc1912.zones,根据需要添加正向和反响解析区域。

zone "centos.org" IN {

type master;

file "centos.org.zone";

allow-update { none; };

};

zone "0.168.192.in-addr.arpa" IN {

type master;

file "0.168.192.zone";

allow-update { none; };

};

下面,将named.rfc1912.zones文件复制一份,并更名为named.other.zones(这个文件名要和named.conf里相应视图内的文件定义要一致哦!)。然后,对named.other.zones文件进行修改。

zone "centos.org" IN {

type master;

file "centos.org1.zone";    //这里修改external的正向解析文件为centos.org1.zone。

allow-update { none; };

};

zone "0.168.192.in-addr.arpa" IN {

type master;

file "0.168.1921.zone";     //这里修改external的反向解析文件为0.168.1921.zone。

allow-update { none; };

};

下面,对区域定义中定义的文件进行配置。下面是internal的区域解析文件:

$TTL          86400

@              IN SOA      x.centos.org.  root.x.centos.org. (

2009101901     ; serial (d. adams)

3H             ; refresh

15M          ; retry

1W            ; expiry

1D )           ; minimum

IN NS                  x.centos.org. 

IN MX       mail.centos.org. 

X                IN A               192.168.0.39

www        IN CNAME   x.centos.org.   //此为正向解析文件

———————————————————————————————————————

$TTL          86400

@              IN SOA      x.centos.org.  root.x.centos.org. (

2009101901     ; serial (d. adams)

3H             ; refresh

15M          ; retry

1W            ; expiry

1D )           ; minimum

IN NS                  x.centos.org. 

39          IN PTR       x.centos.org.   //此为逆向解析文件

这里,internal的正向解析文件为centos.org.zone,逆向解析文件为0.168.192.zone;external的正向解析文件为centos.org1.zone,逆向解析文件为0.168.1921.zone。两个视图的解析文件配置方法一样,只是IP地址不同。可以先将internal的解析文件配置好,然后复制一份并更名,然后稍作修改即可。

一切修改完毕后,重启DNS服务器,然后进行测试即可。

DNS的view设置的更多相关文章

  1. 导航栏和里面的View设置的是同一颜色值,实际运行又不一样.

    导航栏和里面的View设置的是同一颜色值,实际运行又不一样.如何保证两者的颜色一致呢?  答案就是:( navigationBar.translucent = NO; )   去除 导航条的分割线(黑 ...

  2. 为View设置左右切换动画

    本文同步自http://javaexception.com/archives/64 问题: 近期的需求中,碰到了一个view切换动画的需求.要实现的是点击按钮,从左到右滑动view,左边的view消失 ...

  3. Linux查看DNS服务器及设置DNS服务器

    DNS(Domain Name System,域名系统),因特网上作为域名和IP地址相互映射的一个分布式数据库,能够使用户更方便的访问互联网,而不用去记住能够被机器直接读取的IP数串. 一台主机的dn ...

  4. linux 虚拟机设置好固定ip 修改了 dns 网络需要设置成桥接模式

    linux  虚拟机设置好固定ip 修改了 dns  网络需要设置成桥接模式  可以修复网络连接(浏览器返回 server not  found)

  5. 阶段一:为View设置阴影和弹出动画(天气应用)

    “阶段一”是指我第一次系统地学习Android开发.这主要是对我的学习过程作个记录. 上一篇阶段一:通过网络请求,获得并解析JSON数据(天气应用)完成了应用的核心功能,接下来就要对它进行优化.今天我 ...

  6. android给View设置上下左右边框

    给View控件设置边框,可以动态设置上下左右.通过布局文件就能搞定 1.在drawable文件夹下新建一个shape_main_list_bg.xml文件 <layer-list xmlns:a ...

  7. iOS 中如何将View设置为圆角的矩形?

    今天刚好需要添加一个圆角的view. 必须先导入头文件. #import <QuartzCore/QuartzCore.h> bgView.layer.cornerRadius = cor ...

  8. 给任意view设置圆角outline.setRoundRect()方法实现

    效果图,给banner设置圆角,1没有直接修改imageView而是使用自带方法进行设置 具体方法如下 //圆角方法 @TargetApi(Build.VERSION_CODES.LOLLIPOP) ...

  9. docker的常用操作之二:docker内无法解析dns之firewalld设置等

    一,如何启动一个已退出的容器? [root@localhost ~]# docker start storage4 说明:架构森林是一个专注架构的博客,地址:https://www.cnblogs.c ...

随机推荐

  1. 用任意语言与WebService进行交互

    using System; using System.Web.Services; using YY.SmsPlatform.Common.Objects; using YY.SmsPlatform.C ...

  2. ajax省市区三级联动

    jdbc+servlet+ajax开发省市区三级联动 技术点:jdbc操作数据库,ajax提交,字符拦截器,三级联动 特点:局部刷新达到省市区三级联动,举一反三可以做商品分类等 宗旨:从实战中学习 博 ...

  3. (引用)Python 元素、元组、列表、字典的区别

    转载:http://www.th7.cn/Program/Python/201407/231060.shtml 元素: 元组:tuple=('nice','to','meet','you') 列表:l ...

  4. 什么是IO流 \ 以及文件输入输出

    一.IO流的分类: 流按照操作数据的类型分为两种:字节流:字符流. 1.什么是字节流:读取的是文件的二进制数据,不会对二进制做处理,不会解析成看得懂的数据. 2.什么是字符流:读取的是文件的二进制数据 ...

  5. JS浮点数的加减乘除运算

    文章来源地址:http://blog.csdn.net/lyd518/article/details/7236464 转载请注明出处,尊重作者劳动成果,谢谢!问题这样的: 37.5*5.5=206.0 ...

  6. LSD-SLAM深入学习(4)-非ROS改造

    前言 没错,距离上一次博客的发布已经俩月了,今天是圣诞节,圣诞快乐. 在前几篇中已经完成了ROS下面的一系列操作.如有任何问题,feel free to contact me at robotsmin ...

  7. MySQL-Front 建表引发的一点小思考(数据表格模版)

    我们建表的时候,有一些字段总是会常用到的.也就是每一张表都会有这些字段. 我用mysql有一点时间了,今天(2016-02-27 21:53:38)在用mysql-front建表的时候,感觉有点点不太 ...

  8. Keepalived 配置实例

    Keepalived 是一款轻量级HA集群应用,它的设计初衷是为了做LVS集群的HA,即探测LVS健康情况,从而进行主备切换,不仅如此,还能够探测LVS代理的后端主机的健康状况,动态修改LVS转发规则 ...

  9. Java常用的7大排序算法汇总

    1.插入排序算法 插入排序的基本思想是在遍历数组的过程中,假设在序号 i 之前的元素即 [0..i-1] 都已经排好序,本趟需要找到 i 对应的元素 x 的正确位置 k ,并且在寻找这个位置 k 的过 ...

  10. win2008 IIS与tomcat整合

    1.在tomcat目录下新建jk文件夹 2. Copy isapi_redirect.dll到jk,并新建一个isapi_redirect.properties配置文件,内容如下: extension ...