虚拟机怎么架设dns服务器,虚拟机centos7 DNS服务器搭建

2023-10-27

服务器端:

前期工作:

切换到NAT模式

(1)关闭防火墙以及SeLinux.

防火墙相关设置:

systemctl stop firewalld  //临时关闭防火墙

systemctl disable firewalld  //禁止开机启动防火墙

selinux相关设置:

SeLinux配置文件,/etc/selinux/config

设置 SELINUX=disabled

(2)安装相应的软件包

yum -y install bind

yum -y install bind-utils  //bind-utils提供DNS查询工具,如dig、host、nslookup

安装完后,检测有没有安装

[root@localhost ~]# rpm -qa | grep bind

rpcbind-0.2.0-42.el7.x86_64

bind-libs-9.9.4-61.el7.x86_64

bind-libs-lite-9.9.4-61.el7.x86_64

bind-license-9.9.4-61.el7.noarch

bind-9.9.4-61.el7.x86_64

bind-utils-9.9.4-61.el7.x86_64

切换到OnlyHost模式

(3)修改配置文件

配置文件路径: /etc/named.conf

示例配置文件:

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

拷贝示例配置文件到tmp文件夹下

cp /usr/share/doc/bind-9.9.4/sample/etc/named.conf  /tmp

(4)重启服务

systemctl restart named

systemctl enable named  //开机启动DNS服务

客户端:

切换到NAT模式下:

yum -y install bind-utils

切换到OnlyHost模式下:

配置文件 :/etc/resolv.conf

添加如下:

nameserver 192.168.59.128(DNS IP地址)

注意问题:

(1)格式问题 (紧靠左边,'.')

(2)权限问题(copy named.empty(默认权限640) 来编写正反向解析文件,记得chmod 644正向解析文件,chmod 644反向解析文件,如果自己新建正反向解析文件,那么不存在解析问题)

出错处理:

1.服务启动后报错信息

2.如果服务没有报错信息,但是没有出现指定效果,tail -30 /var/log/messages

3.google/baidu  相关错误信息

课堂案例项目:

搭建fqnu.org网站域名系统

域名

IP地址

dns.fqnu.org

192.168.59.128

dxxy.fqnu.org

192.168.59.120

jgxy.fqnu.org

192.168.59.121

wfxy.fqnu.org

192.168.59.123

运行效果图:

客户端运行效果:

[root@localhost ~]# host wfxy.fqnu.org

wfxy.fqnu.org has address 192.168.59.123

[root@localhost ~]# host 192.168.59.123

123.59.168.192.in-addr.arpa domain name pointer wfxy.fqnu.org.

[root@localhost ~]# host 192.168.59.120

120.59.168.192.in-addr.arpa domain name pointer dxxy.fqnu.org.

[root@localhost ~]# host 192.168.59.121

121.59.168.192.in-addr.arpa domain name pointer jgxy.fqnu.org.

[root@localhost ~]# host jgxy.fqnu.org

jgxy.fqnu.org has address 192.168.59.121

[root@localhost ~]# host 192.168.59.128

128.59.168.192.in-addr.arpa domain name pointer dns.fqnu.org.

[root@localhost ~]# host 192.168.59.129

Host 129.59.168.192.in-addr.arpa. not found: 3(NXDOMAIN)

[root@localhost ~]# host tyxy.fqnu.org

Host tyxy.fqnu.org.localdomain not found: 2(SERVFAIL)

[root@localhost ~]#

课堂案例项目 DNS配置文件如下:

路径: /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 {

directory "/var/named";

dump-file "/var/named/data/cache_dump.db";

statistics-file "/var/named/data/named_stats.txt";

};

zone "fqnu.org" {

type master;

file "fqnu.org";

};

zone "59.168.192.in-addr.arpa" {

type master;

file "59.168.192";

};

正向解析文件如下:

/var/named/fqnu.org

$TTL 86400

fqnu.org. IN SOA dns.fqnu.org. root.fqnu.org (

20180511 ; serial

1H ; refresh

15M ; retry

1W ; expire

1D ) ; minimum

fqnu.org. IN NS dns.fqnu.org.

dns         IN A 192.168.59.128

dxxy IN A 192.168.59.120

jgxy IN A 192.168.59.121

wfxy IN A 192.168.59.123

反向解析文件:

$TTL 86400

@ IN SOA 59.168.192.in-addr.arpa. root.fqnu.org (

20180511 ; serial

1H ; refresh

15M ; retry

1W ; expire

1D ) ; minimum

@ IN NS dns.fqnu.org.

128 IN PTR dns.fqnu.org.

120 IN PTR dxxy.fqnu.org.

121 IN PTR jgxy.fqnu.org.

123 IN PTR wfxy.fqnu.org.

DNS示例配置文件如下:

/*

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 about the

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

*/

options

{

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

directory "/var/named"; // "Working" directory

dump-file "data/cache_dump.db";

statistics-file "data/named_stats.txt";

memstatistics-file "data/named_mem_stats.txt";

/*

Specify listenning interfaces. You can use list of addresses (';' is

delimiter) or keywords "any"/"none"

*/

//listen-on port 53 { any; };

listen-on port 53 { 127.0.0.1; };

//listen-on-v6 port 53 { any; };

listen-on-v6 port 53 { ::1; };

/*

Access restrictions

There are two important options:

allow-query { argument; };

- allow queries for authoritative data

allow-query-cache { argument; };

- allow queries for non-authoritative data (mostly cached data)

You can use address, network address or keywords "any"/"localhost"/"none" as argument

Examples:

allow-query { localhost; 10.0.0.1; 192.168.1.0/8; };

allow-query-cache { ::1; fe80::5c63:a8ff:fe2f:4526; 10.0.0.1; };

*/

allow-query { localhost; };

allow-query-cache { localhost; };

/* Enable/disable recursion - recursion yes/no;

- 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 related options. See information about keys ("Trusted keys", bellow) */

/* Enable serving of DNSSEC related data - enable on both authoritative

and recursive servers DNSSEC aware servers */

dnssec-enable yes;

/* Enable DNSSEC validation on recursive servers */

dnssec-validation yes;

/* In RHEL-7 we use /run/named instead of default /var/run/named

so we have to configure paths properly. */

pid-file "/run/named/named.pid";

session-keyfile "/run/named/session.key";

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

};

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;

};

};

/*

Views let a name server answer a DNS query differently depending on who is asking.

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

"default" view, which matches all clients.

Views are processed sequentially. The first match is used so the last view should

match "any" - it's fallback and the most restricted view.

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

*/

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

recursion yes;

# all views must contain the root hints zone:

zone "." IN {

type hint;

file "/var/named/named.ca";

};

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

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

* not leak to the other nameservers:

*/

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 { localnets; };

recursion yes;

zone "." IN {

type hint;

file "/var/named/named.ca";

};

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

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

* not leak to the other nameservers:

*/

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

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

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

/*

NOTE for dynamic DNS zones and secondary zones:

DO NOT USE SAME FILES IN MULTIPLE VIEWS!

If you are using views and DDNS/secondary zones it is strongly

recommended to read FAQ on ISC site (www.isc.org), section

"Configuration and Setup Questions", questions

"How do I share a dynamic zone between multiple views?" and

"How can I make a server a slave for both an internal and an external

view at the same time?"

*/

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 "dynamic/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/dnssec-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 match any above view:

*/

match-clients { any; };

zone "." IN {

type hint;

file "/var/named/named.ca";

};

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

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

};

};

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

虚拟机怎么架设dns服务器,虚拟机centos7 DNS服务器搭建 的相关文章

  • 阿里前端实习电话面(一面)(被捞两次)

    学习前端时长一年半 以下是电话面试阿里前端被问的一些知识点 都是下来回顾的 某一天我接到了阿里的hr电话 约面试时间 我以为阿里和其他公司一样会发邮件给我 所以一直在等 结果我在实验室接到了电话 说今天面试 我说没收到邮件 可以等我半小时
  • RabbitMQ实现延迟消息【死信队列实现、插件实现】

    视频地址 之前一直没使用过RabbitMQ 最近有一个需求需要用到延迟消息 就简单的使用了一下 发现还是有蛮多坑的 此篇文章只是RabbitMQ延迟消息相关内容 至于安装RabbitMQ等其它操作 参考百度 一 什么是延迟消息 顾问思议所谓
  • 详解命令执行漏洞

    详解命令执行漏洞 漏洞描述 漏洞原理 漏洞危害 漏洞产生的原因 命令执行与代码执行的区别 常见的危险函数 命令执行的类型 危险函数利用 system passthru exec shell exec 反引号 escapeshellarg e
  • 心流:最优体验心理学

    心流的成因和特征 注意力 体验过心流的人都知道 那份深沉的快乐是严格的自律 集中注意力换来的 有一个他愿意为之付出的目标 那目标是什么不要紧 只要那目标将他的注意力集中于此 有即时的回馈 因全神贯注于此 日常恼人的琐事被忘却和屏蔽 达到了忘
  • goland插件推荐Rider UI Theme Pack

    推荐一个goland配色插件Rider UI Theme Pack 里面自带visual assist配色 配色截图如下 直接在plugins里面进行搜索或者在插件home page下载后进行安装 然后按照下图进行设置即可 此插件还适用于J
  • LNK 2019 无法解析的外部符号

    原因 你包含了头文件 却没有包含该文件的库文件 lib lib文件 lib是静态数据链接库 在windows中起到链接程序和函数的作用 lib里存放的是函数调用的信息 数据库有静态数据库 lib 和动态数据库 dll 两种 静态编译 个人理
  • 如何重写hashCode()和equals()方法

    转载 http blog csdn net neosmith article details 17068365 hashCode 和equals 方法可以说是Java完全面向对象的一大特色 它为我们的编程提供便利的同时也带来了很多危险 这篇
  • gsoap实现webservice如何发送结构体数组

    头文件中如下定义 struct SRecordArray int size struct SRecord ptr 注意加粗那一行 二维指针前定义一个 size才能正确发送出多个结构体数据 不然只能发出一个
  • Android-P模拟器镜像编译

    0 前言 为模拟器编译镜像和为真机编译有所不同 本文梳理Android P为模拟器编译源码的方法 1 aosp 1 1 aosp arm eng 根据参考资料 1 的方式 编译源码之后 直接执行emulator即可启动模拟器 但会提示 图1
  • IDEA如何将Git回退到某个版本

    网上资料大多是 reset current branch to here 之后 选hard模式 然后强制push的方式 虽然能将本地及远程仓库都恢复到某次提交 但是不会产生commit记录 导致在该分支共同开发的其他人下次提交时 会把你已经
  • Networkx报错 AttributeError: 'NodeView' object has no attribute 'remove'

    错误描述 我用的版本是python2 7 networkx2 2 部分代码 G2是传入的一个随机网络 unsaturated b G2 nodes unsaturated b remove node b 最后一行报错 提示Attribute
  • 虚拟化存储技术

    文章目录 前言 一 HCLA存储技术趋势与智能存储组件 1 HCLA存储技术趋势 1 什么是数据存储 2 数据存储系统 3 数据分类 4 数据存储发展趋势 小结 2 智能存储组件 控制框 硬盘框 级联模块 硬盘 接口模块 二 虚拟化与网络存
  • C++的std::for_each()

    当给定一个容器范围 我们通常需要对其中的每个元素执行相同的操作 这样的操作可能包括打印元素 修改元素的值或应用一个自定义函数等等 在 C 标准库中 std for each 算法函数提供了一种方便的方式来对容器范围内的元素执行指定的操作 s
  • Golang空结构体struct{}的作用是什么?

    文章目录 占位符 通道标识 键集合 内存占用优化 总结 在Go语言中 空结构体 struct 是一种特殊的数据类型 它不占用任何内存空间 空结构体没有任何字段 也没有任何方法 尽管它看起来没有实际的用途 但在编程中确实有一些常见的应用场景
  • Handler dispatch failed; nested exception is java.lang.NoSuchMethodError

    一 问题描述 1 报错 org springframework web util NestedServletException Handler dispatch failed nested exception is java lang No
  • 清华智能体宇宙火了,AI模拟“囚徒困境”等实验只需几行简单配置

    丰色 发自 凹非寺量子位 公众号 QbitAI 可以轻松模拟社会实验的多智能体宇宙来了 它由清华大学联合北邮 微信团队推出 目前已在GitHub揽获1 1k标星 名字简单粗暴 就叫 AgentVerse 划重点 这个环境专门针对大语言模型开
  • 蓝桥杯试题 入门训练 Fibonacci数列 C、C++

    蓝桥杯试题 入门训练 Fibonacci数列 C C 问题描述 Fibonacci数列的递推公式为 Fn Fn 1 Fn 2 其中F1 F2 1 当n比较大时 Fn也非常大 现在我们想知道 Fn除以10007的余数是多少 输入格式 输入包含
  • SpringBoot 日志信息输出

    今天启动SpringBoot项目发现 大于许多日志信息 但是大部分提示是 那些注解类没有被使用 日志输出信息如下 CodecsAutoConfiguration matched ConditionalOnClass found requir
  • [echarts]横向柱状图的两种简便画法

    示例图 第一种方法 可以随意控制y左轴和y右轴的显示位置 let option 柱状图的位置 grid left 0 right 0 bottom 0 top 0 containLabel false 图表两侧是否留白 dataZoom t

随机推荐