合理的配置DNS的查询方式

实验环境:

虚拟机:VMware® Workstation 15 Pro

均使用NAT连接   网段为192.168.1.0/24

DNS 服务器 ---- Centos 7.4

内核版本  Kernel: Linux 3.10.0-693.el7.x86_64

IP地址:192.168.1.1/24

网关: 192.168.1.254

DNS: 192.168.1.1

客户端 ---- Centos 7.4

内核版本  Kernel: Linux 3.10.0-693.el7.x86_64

IP地址:192.168.1.2/24

网关: 192.168.1.254

DNS: 192.168.1.1

安装DNS服务

[root@localhost ~]#yum install bind -y                //安装

Loaded plugins: fastestmirror, langpacks

repo                                                            | 3.6 kB  ::    

Determining fastest mirrors

Resolving Dependencies

--> Running transaction check

---> Package bind.x86_64 :9.9.-.el7 will be installed

--> Finished Dependency Resolution

Dependencies Resolved

=======================================================================================

 Package         Arch              Version                       Repository       Size

=======================================================================================

Installing:

 bind            x86_64            :9.9.-.el7               repo            1.8 M

Transaction Summary

=======================================================================================

Install   Package

Total download size: 1.8 M

Installed size: 4.3 M

Downloading packages:

Running transaction check

Running transaction test

Transaction test succeeded

Running transaction

  Installing : :bind-9.9.-.el7.x86_64                                         /

  Verifying  : :bind-9.9.-.el7.x86_64                                         /

Installed:

  bind.x86_64 :9.9.-.el7                                                         

Complete!

[root@localhost ~]#

编辑dns服务器配置文件

[root@localhost ~]# vim /etc/named.conf

//

// named.conf

//

// Provided by Red Hat bind package to configure the ISC BIND named(8) DNS // server as a caching only nameserver (as a localhost DNS resolver only).

//

// See /usr/share/doc/bind*/sample/ for example named configuration files.

//

// See the BIND Administrator's Reference Manual (ARM) for details about the

// configuration located in /usr/share/doc/bind-{version}/Bv9ARM.html

options {

listen-on port { 127.0.0.1; }; //修改为listen-on port 53 { any; };

listen-on-v6 port { ::; }; //修改为linsten-on-v6 port 53 { any; };

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";

allow-query { localhost; }; //修改为allow-query { any; };

/*

- 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 yes;

dnssec-validation yes;

/* 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;

};

};

zone "." IN {

type hint;

file "named.ca";

};

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

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

编辑DNS正反向区域

 [root@localhost named]# vim /etc/named.rfc1912.zones
// named.rfc1912.zones:
//
// Provided by Red Hat caching-nameserver package
//
// ISC BIND named zone configuration for zones recommended by
// RFC 1912 section 4.1 : localhost TLDs and address zones
// and http://www.ietf.org/internet-drafts/draft-ietf-dnsopdefault-local-zones-02.txt
// (c)2007 R W Franks
//
// See /usr/share/doc/bind*/sample/ for example named configuration files.
//
zone "localhost.localdomain" IN {
type master;
file "named.localhost";
allow-update { none; };
}; zone "localhost" IN {
type master;
file "named.localhost";
allow-update { none; };
}; zone "1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.ip6.arpa" IN {
type master;
file "named.loopback";
allow-update { none; };
}; zone "1.0.0.127.in-addr.arpa" IN {
type master;
file "named.loopback";
allow-update { none; };
}; zone "0.in-addr.arpa" IN {
type master;
file "named.empty";
allow-update { none; };
}; //-------------------------------------------//在最底下添加下面两段
//第一段为正向解析
zone "netdj.net" IN {
type master;
file "netdj.net.zone";
allow-update { none; };
}; //第二段为反向解析
zone "1.168.192.in-addr.arpa" IN {
type master;
file "1.168.192.zone";
allow-update { none; };
};

创建DNS正反向区域解析文件

[root@localhost ~]# cd /var/named/
[root@localhost named]# ls
data dynamic named.ca named.empty named.localhost named.loopback slaves
//复制模板创建正反向解析文件
[root@localhost named]# cp -p named.empty netdj.net.zone
[root@localhost named]# cp -p named.empty 1.168..zone

编辑正向解析文件

 [root@localhost named]# vim netdj.net.zone
$TTL 3H
@ IN SOA @ rname.invalid. (
; serial
1D ; refresh
1H ; retry
1W ; expire
3H ) ; minimum
NS @
A 127.0.0.1
dns A 192.168.1.1 //使用A记录将dns.netdj.net指向192.168.1.1
client A 192.168.1.2 //使用A记录将client.netdj.net指向192.168.1.2

编辑反向解析文件

 [root@localhost named]# vim 1.168..zone
$TTL 3H
@ IN SOA @ rname.invalid. (
; serial
1D ; refresh
1H ; retry
1W ; expire
3H ) ; minimum
NS @
A 127.0.0.1
PTR dns.netdj.net. //使用PTR记录将192.168.1.1指向dns.netdj.net
PTR client.netdj.net. //使用PTR记录将192.168.1.2指向client.netdj.net

重启服务

[root@localhost named]# systemctl restart named //重启服务
[root@localhost named]# systemctl enable named //开机自启动
Created symlink from /etc/systemd/system/multi-user.target.wants/named.service to /usr/lib/systemd/system/named.service.

关闭防火墙、selinux

[root@localhost named]# systemctl stop firewalld.service
[root@localhost named]# setenforce //临时生效,重启后失效

服务端测试

[root@localhost named]# nslookup
> dns.netdj.net
Server: 192.168.1.1
Address: 192.168.1.1# Name: dns.netdj.net
Address: 192.168.1.1
> client.netdj.net
Server: 192.168.1.1
Address: 192.168.1.1# Name: client.netdj.net
Address: 192.168.1.2
> exit [root@localhost named]#

客户端测试

[root@localhost ~]# nslookup
> dns.netdj.net
Server: 192.168.1.1
Address: 192.168.1.1# Name: dns.netdj.net
Address: 192.168.1.1
> client.netdj.net
Server: 192.168.1.1
Address: 192.168.1.1# Name: client.netdj.net
Address: 192.168.1.2
> exit [root@localhost ~]#

DNS服务搭建完成!!

限制区域传送,可实现两个IP之间的区域传送。避免黑客的缓存投毒进而利用虚假IP地址替换域名系统表中的地址造成破坏。此外还可以防止注册劫持,DNS欺骗等攻击

 [root@localhost named]# vim /etc/named.rfc1912.zones
// named.rfc1912.zones:
//
// Provided by Red Hat caching-nameserver package
//
// ISC BIND named zone configuration for zones recommended by
// RFC 1912 section 4.1 : localhost TLDs and address zones
// and http://www.ietf.org/internet-drafts/draft-ietf-dnsop-default-local-zones-02.txt
// (c)2007 R W Franks
//
// See /usr/share/doc/bind*/sample/ for example named configuration files.
// zone "localhost.localdomain" IN {
    type master;
    file "named.localhost";
    allow-update { none; };
}; zone "localhost" IN {
    type master;
    file "named.localhost";
    allow-update { none; };
}; zone "1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.ip6.arpa" IN {
    type master;
    file "named.loopback";
    allow-update { none; };
}; zone "1.0.0.127.in-addr.arpa" IN {
    type master;
    file "named.loopback";
    allow-update { none; };
}; zone "0.in-addr.arpa" IN {
    type master;
    file "named.empty";
    allow-update { none; };
}; zone "netdj.net" IN {
    type master;
    file "netdj.net.zone";
    allow-update { none; }; //修改为allow-transfer { 192.168.1.1;192.168.1.2; };
}; zone "1.168.192.in-addr.arpa" IN {
    type master;
    file "1.168.192.zone";
    allow-update { none; }; //修改为allow-transfer { 192.168.1.1;192.168.1.2; };
};

修改DNS配置查询,可实现仅指定网段主机查询DNS信息。以保障DNS服务器不易被黑客发现并攻击。

 [root@localhost named]# vim /etc/named.conf
//
// named.conf
//
// Provided by Red Hat bind package to configure the ISC BIND named(8) DNS
// server as a caching only nameserver (as a localhost DNS resolver only).
//
// See /usr/share/doc/bind*/sample/ for example named configuration files.
//
// See the BIND Administrator's Reference Manual (ARM) for details about the
// configuration located in /usr/share/doc/bind-{version}/Bv9ARM.html options {
listen-on port { any; };
listen-on-v6 port { any; };
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";
allow-query { any; }; //修改为allow-query { 192.168.1.0/24; }; /*
- 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 yes;
dnssec-validation yes; /* 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;
};
}; zone "." IN {
type hint;
file "named.ca";
}; include "/etc/named.rfc1912.zones";
include "/etc/named.root.key";

本文由博主亲测有效,若有错误请评论指出谢谢

----------持续更新中

玩转DNS服务器——Bind服务的更多相关文章

  1. centos6.5环境DNS-本地DNS服务器bind的搭建

    centos6.5环境DNS-本地DNS服务器bind的搭建 域名系统(英文:Domain Name System,缩写:DNS)是因特网的一项服务.它作为将域名和IP地址相互映射的一个分布式数据库, ...

  2. 内建DNS服务器--BIND

    参考 BIND 官网:http://www.isc.org/downloads/bind/ 1.系统环境说明 [root@clsn6 ~]# cat /etc/redhat-release CentO ...

  3. Debian9.5系统DNS服务器BIND软件配置说明

    DNS的出现的历史 网络出现的早期是使用IP地址通讯的,那时就几台主机通讯.但是随着接入网络主机的增多,这种数字标识的地址非常不便于记忆,UNIX上就出现了建立一个叫做hosts的文件(Linux和W ...

  4. CentOS7-1810 系统DNS服务器BIND软件配置说明

    DNS的出现的历史 网络出现的早期是使用IP地址通讯的,那时就几台主机通讯.但是随着接入网络主机的增多,这种数字标识的地址非常不便于记忆,UNIX上就出现了建立一个叫做hosts的文件(Linux和W ...

  5. Centos7.3搭建DNS服务器--BIND

    1.系统环境说明 [root@dns-server etc]# cat /etc/redhat-release CentOS Linux release (Core) 防火墙和Selinux关闭 [r ...

  6. centos7 主从dns配置 bind服务

    一,配置前请先关闭防火墙selinux 防火墙关闭方法,参见上一篇文章. setenforce 0    #临时关闭 修改/etc/selinux/config 文件  将SELINUX=enforc ...

  7. redhat配置dns服务器bind

    配置Oracle11g的RAC需要使用DNS服务器来解析SCAN IP,本文就是以此为例介绍bind服务器的使用.首先科普一下bind服务器,属于企业级产品了,还是开源的: Bind是Berkeley ...

  8. 搭建DNS服务器-bind

    1. 安装 yum install -y bind-chroot yum install -y bind-utils service named-chroot start    2. 修改配置 增加一 ...

  9. 简单搭建DNS服务器——bind

    1安装bind yum install -y bind bind-utils bind-chroot 2 修改配置文件 # grep '^[^#]' /etc/named.conf options { ...

随机推荐

  1. Ubuntu上使用Docker打包镜像

    关于这个一开始会有点懵,直白一点就是,把本地路径下的代码放到docker里面去,然后在docker这个隔离环境中运行调用我们的程序.专业解释请自行检索学习. 第一步:创建容器 docker run - ...

  2. Kubernetes平台环境搭建

    软件 版本 Linux操作系统 CentOS7.4 Kubernetes 1.12 Docker 18.xx-ce Etcd 3.x Flannel 0.10 角色 IP 组件 推荐配置 master ...

  3. 学习数据结构Day1

    数据结构的分类: 线性结构 数组:栈:队列:链表:哈希表:... 树结构 二叉树:二分查找树:AVL;红黑树:Treap:Splay:堆:栈:Trie:线段树:K-D树:并查集:哈夫曼         ...

  4. [转帖]70亿!以色列间谍产品公司NSO要被卖掉了

    70亿!以色列间谍产品公司NSO要被卖掉了 2017-06-14 11:11 https://www.sohu.com/a/148739327_257305 E安全6月14日讯以色列的网络能力处于世界 ...

  5. Python知识点总结篇(五)

    软件目录结构规范 目标: 提高可读性: 提高可维护性: 常见结构 Demo/ |-- bin/ #存放项目的一些可执行文件 | |-- demo #可执行程序,启动demo调main.py | |-- ...

  6. 深度学习-Wasserstein GAN论文理解笔记

    GAN存在问题 训练困难,G和D多次尝试没有稳定性,Loss无法知道能否优化,生成样本单一,改进方案靠暴力尝试 WGAN GAN的Loss函数选择不合适,使模型容易面临梯度消失,梯度不稳定,优化目标不 ...

  7. LeetCode runtime error

    今天在写LeetCode的某一道题目时候,遇到runtime error问题,本地能过,submit后死活不能通过. 查了一下网上的一些答案,基本上都是数组.指针没有初始化造成野指针.数组索引值越界. ...

  8. C# vb .net实现相机视图效果滤镜

    在.net中,如何简单快捷地实现Photoshop滤镜组中的相机视图效果呢?答案是调用SharpImage!专业图像特效滤镜和合成类库.下面开始演示关键代码,您也可以在文末下载全部源码: 设置授权 第 ...

  9. selenium中元素操作之简单的鼠标、键盘操作(三)

    1.鼠标操作导入类:ActionChains --鼠标的操作形成一连串的动作链,由selenium的ActionChains类来完成模拟鼠标操作手表操作的过程:1.鼠标的操作,先放到一个列表中2.利用 ...

  10. EF CodeFirst Dome学习

    创建ConsoleDome控制台应用程序 从NuGet包管理器安装EntityFramework 创建DbContextDome类并继承DbContext public class DbContext ...