Ubuntu 12.04 DNS服务器的配置方法
Bind是一款开放源码的DNS服务器软件,由美国加州大学Berkeley分校开发和维护的,全名为Berkeley Internet Name Domain它是目前世界上使用最为广泛的DNS服务器软件,支持各种unix平台和windows平台。
一、安装bind
1、检查是否已安装bind
# dpkg -l |grep bind
2、安装bind9
# apt-get install bind9
再次检查,现在已经安装成功了。
root@nfsserver:~# dpkg -l |grep bind
ii bind9 1:9.8.1.dfsg.P1-4ubuntu0.10 Internet Domain Name Server
DNS配置文件在/etc/bind目录中,查看bind安装目录
root@nfsserver:/etc/bind# ls -l
total 52
-rw-r--r-- 1 root root 2389 Feb 18 21:45 bind.keys
-rw-r--r-- 1 root root 237 Feb 18 21:45 db.0
-rw-r--r-- 1 root root 271 Feb 18 21:45 db.127
-rw-r--r-- 1 root root 237 Feb 18 21:45 db.255
-rw-r--r-- 1 root root 353 Feb 18 21:45 db.empty
-rw-r--r-- 1 root root 270 Feb 18 21:45 db.local
-rw-r--r-- 1 root root 2994 Feb 18 21:45 db.root
-rw-r--r-- 1 root bind 463 Feb 18 21:45 named.conf
-rw-r--r-- 1 root bind 490 Feb 18 21:45 named.conf.default-zones
-rw-r--r-- 1 root bind 165 Feb 18 21:45 named.conf.local
-rw-r--r-- 1 root bind 890 Mar 20 14:37 named.conf.options
-rw-r----- 1 bind bind 77 Mar 20 14:37 rndc.key
-rw-r--r-- 1 root root 1317 Feb 18 21:45 zones.rfc1918
安装bind9后会生成如下三个配置文件:named.conf,named.conf.options,named.conf.local 。
其中name.conf是主配置文件,里面包含了name.conf.options和named.conf.local。我们在假设本地dns时,只需要改动named.conf.local即可。
root@nfsserver:/etc/bind# cat named.conf
// This is the primary configuration file for the BIND DNS server named.
//
// Please read /usr/share/doc/bind9/README.Debian.gz for information on the
// structure of BIND configuration files in Debian, *BEFORE* you customize
// this configuration file.
//
// If you are just adding zones, please do that in /etc/bind/named.conf.local include "/etc/bind/named.conf.options";
include "/etc/bind/named.conf.local";
include "/etc/bind/named.conf.default-zones";
3、name.conf.options配置
root@nfsserver:/etc/bind# cat named.conf.options
options {
directory "/var/cache/bind"; // If there is a firewall between you and nameservers you want
// to talk to, you may need to fix the firewall to allow multiple
// ports to talk. See http://www.kb.cert.org/vuls/id/800113 // If your ISP provided one or more IP addresses for stable
// nameservers, you probably want to use them as forwarders.
// Uncomment the following block, and insert the addresses replacing
// the all-0's placeholder. forwarders {
8.8.8.8;
8.8.4.4;
0.0.0.0;
}; //========================================================================
// If BIND logs error messages about the root key being expired,
// you will need to update your keys. See https://www.isc.org/bind-keys
//========================================================================
dnssec-validation auto; auth-nxdomain no; # conform to RFC1035
listen-on-v6 { any; };
};
该配置文件用来设置bind的forwards 地址。当bind遇到不能解析的IP地址时,它会交给forwards address DNS去处理。
二、环境和需求
Server的ip:10.1.101.188
Client的ip范围为10.1.101.1——10.1.101.254相互能Ping通。
现在将Server架设成主dns服务器,任务的需求是能解析
master.lxy.com 10.1.101.11
www.lxy.com 10.1.101.11
slave1.lxy.com 10.1.101.12
slave2.lxy.com 10.1.101.15
分析:根据上面的主机名和对应ip可以看出:
- 需要添加正向区域"lxy.com"和反向区域"101.1.10.in-addr.arpa".
- 在"lxy.com"区域中添加A记录master对应10.1.101.11,CNAME(别名记录)记录www对应master
- 在"101.1.10.in-addr.arpa"区域中添加各个ip地址对应的主机名
三、配置
1、编辑name.conf.local
root@nfsserver:/etc/bind# cat named.conf.local
//
// Do any local configuration here
// // Consider adding the 1918 zones here, if they are not used in your
// organization
//include "/etc/bind/zones.rfc1918"; //正向解析域
zone "lxy.com"{
type master; #定义DNS服务器为主DNS
file "/etc/bind/db.lxy.com";
};
# For reverse DNS
//反向解析域
zone "101.1.10.in-addr.arpa"{
type master;
notify no;
file "/etc/bind/rev.101.1.10.in-addr.arpa.";
};
反解析zone名称定义规定前部分ip倒着写。如ip 192.168.1.2,名称定义为1.168.192.in-addr.arpa。
2、新建name.conf.local中指定的区域文件
在/etc/bind下新建正向区域文件(复制一份)
命令:# cp /etc/bind/db.local /etc/bind/db.lxy.com
root@nfsserver:/etc/bind# cp db.local db.lxy.com
root@nfsserver:/etc/bind# ls
bind.keys db.127 db.empty db.lxy.com named.conf named.conf.local rndc.key
db.0 db.255 db.local db.root named.conf.default-zones named.conf.options zones.rfc1918
root@nfsserver:/etc/bind#
在/etc/bind下新建反向区域文件(复制一份)
命令:cp /etc/bind/db.127 /etc/bind/rev.101.1.10.in-addr.arpa
root@nfsserver:/etc/bind# cp db.127 rev.101.1.10.in-addr.arpa
root@nfsserver:/etc/bind# ls
bind.keys db.127 db.empty db.lxy.com named.conf named.conf.local rev.101.1.10.in-addr.arpa zones.rfc1918
db.0 db.255 db.local db.root named.conf.default-zones named.conf.options rndc.key
3、编辑正向解析域文件
root@nfsserver:/etc/bind# cat db.lxy.com
;
; BIND data file for local loopback interface
;
$TTL 604800
@ IN SOA localhost. root.localhost. (
2 ; Serial
604800 ; Refresh
86400 ; Retry
2419200 ; Expire
604800 ) ; Negative Cache TTL
;
@ IN NS localhost.
@ IN A 127.0.0.1
@ IN AAAA ::1
master IN A 10.1.101.11
www IN CNAME master
slave1 IN A 10.1.101.12
slave2 IN A 10.1.101.15
4、编辑反向解析域文件
root@nfsserver:/etc/bind# cat rev.101.1.10.in-addr.arpa
;
; BIND reverse data file for local loopback interface
;
$TTL 604800 #指示为每个没有特殊TTL设置的RR给出了一个默认的TTL。
@ IN SOA localhost. root.localhost. ( #定义SOA记录,包括Zone的名字,一个技术联系人和各种不同的超时值。
1 ; Serial
604800 ; Refresh
86400 ; Retry
2419200 ; Expire
604800 ) ; Negative Cache TTL
;
@ IN NS localhost.
1.0.0 IN PTR localhost.
11 IN PTR master.lxy.com
11 IN PTR www.lxy.com
12 IN PTR slave1.lxy.com
15 IN PTR slave2.lxy.com
反解析域可以不设置。
5、重启DNS服务
# service bind9 restart
或者
# /etc/init.d/bind9 restart
四、指定Linux系统使用DNS服务
现在我在10.1.101.189中配置DNS为刚才配置的10.1.101.188。
有一点需要注意不要在/etc/resolv.conf中去修改DNS,重启网络后配置就丢失了。
root@nfsclient:~# cat /etc/resolv.conf
# Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)
# DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN
nameserver 10.1.101.188
在/etc/network/interface中设置DNS
root@nfsclient:~# cat /etc/network/interfaces
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5). # The loopback network interface
auto lo
iface lo inet loopback auto eth0
iface eth0 inet static
address 10.1.101.189
netmask 255.255.255.0
gateway 10.1.101.254
dns-nameservers 10.1.101.188
重启网络,然后就可以ping通刚才配置的域名了。
root@nfsclient:~# cat /etc/resolv.conf
# Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)
# DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN
nameserver 10.1.101.188
root@nfsclient:~# ping -c 4 master.lxy.com
PING master.lxy.com (10.1.101.11) 56(84) bytes of data.
64 bytes from www.lxy.com.101.1.10.in-addr.arpa (10.1.101.11): icmp_req=1 ttl=64 time=0.978 ms
64 bytes from master.lxy.com.101.1.10.in-addr.arpa (10.1.101.11): icmp_req=2 ttl=64 time=0.626 ms
64 bytes from www.lxy.com.101.1.10.in-addr.arpa (10.1.101.11): icmp_req=3 ttl=64 time=0.628 ms
64 bytes from master.lxy.com.101.1.10.in-addr.arpa (10.1.101.11): icmp_req=4 ttl=64 time=0.591 ms --- master.lxy.com ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3005ms
rtt min/avg/max/mdev = 0.591/0.705/0.978/0.161 ms
root@nfsclient:~# ping -c 4 www.lxy.com
PING master.lxy.com (10.1.101.11) 56(84) bytes of data.
64 bytes from www.lxy.com.101.1.10.in-addr.arpa (10.1.101.11): icmp_req=1 ttl=64 time=1.06 ms
64 bytes from master.lxy.com.101.1.10.in-addr.arpa (10.1.101.11): icmp_req=2 ttl=64 time=0.655 ms
64 bytes from www.lxy.com.101.1.10.in-addr.arpa (10.1.101.11): icmp_req=3 ttl=64 time=0.556 ms
64 bytes from master.lxy.com.101.1.10.in-addr.arpa (10.1.101.11): icmp_req=4 ttl=64 time=0.577 ms --- master.lxy.com ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3004ms
rtt min/avg/max/mdev = 0.556/0.714/1.068/0.207 ms
root@nfsclient:~# ping -c 4 slave1.lxy.com
PING slave1.lxy.com (10.1.101.12) 56(84) bytes of data.
64 bytes from slave1.lxy.com.101.1.10.in-addr.arpa (10.1.101.12): icmp_req=1 ttl=64 time=1.07 ms
64 bytes from slave1.lxy.com.101.1.10.in-addr.arpa (10.1.101.12): icmp_req=2 ttl=64 time=0.352 ms
64 bytes from slave1.lxy.com.101.1.10.in-addr.arpa (10.1.101.12): icmp_req=3 ttl=64 time=0.346 ms
64 bytes from slave1.lxy.com.101.1.10.in-addr.arpa (10.1.101.12): icmp_req=4 ttl=64 time=0.321 ms --- slave1.lxy.com ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3004ms
rtt min/avg/max/mdev = 0.321/0.523/1.075/0.319 ms
root@nfsclient:~# ping -c 4 slave2.lxy.com
PING slave2.lxy.com (10.1.101.15) 56(84) bytes of data.
64 bytes from slave2.lxy.com.101.1.10.in-addr.arpa (10.1.101.15): icmp_req=1 ttl=64 time=3.69 ms
64 bytes from slave2.lxy.com.101.1.10.in-addr.arpa (10.1.101.15): icmp_req=2 ttl=64 time=1.63 ms
64 bytes from slave2.lxy.com.101.1.10.in-addr.arpa (10.1.101.15): icmp_req=3 ttl=64 time=1.59 ms
64 bytes from slave2.lxy.com.101.1.10.in-addr.arpa (10.1.101.15): icmp_req=4 ttl=64 time=1.56 ms --- slave2.lxy.com ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3005ms
rtt min/avg/max/mdev = 1.566/2.122/3.696/0.909 ms
root@nfsclient:~#
五、常见错误处理
root@dns:/etc/bind# /etc/init.d/bind9 restart
* Stopping domain name service... bind9 rndc: connect failed: 127.0.0.1#953: connection refused
[ OK ]
* Starting domain name service... bind9 [fail]
原因是在name.conf.local中配置了两个相同的www.teststack.com,删除多余的一条域名记录,然后就可以重启了。
六、资源链接
http://linuxnx.blog.51cto.com/6676498/1169567
了解更多DNS知识推荐一个人的博客:
Ubuntu 12.04 DNS服务器的配置方法的更多相关文章
- 在Ubuntu 12.04系统中安装配置OpenCV 2.4.3的方法
在Ubuntu 12.04系统中安装配置OpenCV 2.4.3的方法 对于,在Linux系统下做图像识别,不像在windows下面我们可以利用Matlab中的图像工具箱来实现,我们必须借助Ope ...
- 在Ubuntu 12.04下采用apt-get的方法安装Qt4
在Ubuntu 12.04下采用apt-get的方法安装Qt4 注:之前发表的一篇博客是采用编译源码的方式安装Qt4,这是很有用的方式,因为源码安装对于所有系统都是通用的,其次,在使用交叉编译器的时候 ...
- [转] Ubuntu 12.04下LAMP安装配置 (Linux+Apache+Mysql+PHP)
我是一个Linux新手,想要安装一台Ubuntu 12.04版的Linux服务器,用这台服务器上的LAMP套件来运行我自己的个人网站.LAMP套件就是 “Linux+Apache+Mysql+PHP这 ...
- Ubuntu 12.04 Desktop下vncserver配置:Unity以及Xfce4桌面环境
将gnome改成xfce xfce-session 即可 2013-01-30 14:45:34| 分类: Ubuntu | 标签:ubuntu12.04 unity vncserver s ...
- Ubuntu 12.04下NFS安装配置图解
以前就听说过nfs服务,但是一直没有用,在学习制作根文件系统的时候,才算是真正用上它了,我感觉它还不错,通过它“挂载”制作好的根文件系统.它在嵌入式中的角色就用下面的一张图说明吧! 用网线将主机与开发 ...
- ubuntu 12.04 nfs-server/client安装配置
由于opennebula的共享存储的方式需要nfs,为了opennebula 3.8在ubuntu 12.04上搭建做铺垫,先介绍下nfs server和client端的安装和配置. 1. nfs ...
- ubuntu 12.04下安装和配置kohana 3.3.3 的方法
一.先到官网下载3.3.3版本的压缩包到/var/www/1117/目录下(提前建好1117的目录)解压 解压好的文件有(applications\modules\system\build.xml\c ...
- Ubuntu 12.04安装vim和配置
问题: ubuntu默认没有安装vim,出现: jyg@ubuntu:~$ vim test.cThe program 'vim' can be found in the following pack ...
- 【linux】Ubuntu 14.04 smba服务器的配置
SMB(Server Messages Block,信息服务块)是为了在ubuntu虚拟机与windows之间共享文件. 具体配置过程如下: (1)安装SMB应用 sudo apt-get in ...
随机推荐
- PHP正则表达式提取超链接及其标题
有这么一段HTML,比较不规则的,如果要提取其中的链接地址和链接名称,怎么弄? //HTML$str = ''<a id="top8" href="http://l ...
- kFreeBSD当前可以做的和不能做的
可以进行FAMP FreeBSD.Apache/Nginx.Mysql/PostGreSQL.PHP/Perl/Python 虚拟化 最易用的VirtualBox 无法安装 Java OpenJDK及 ...
- Eclipse环境下使用Maven注意事项
在最新版本的Eclipse Java EE IDE for Web Developers中已经包含Maven 2 在File,New中可以看到Maven Project,新建, 按照步骤一路下来,要求 ...
- 【JavaEE】SSH+Spring Security+Spring oauth2整合及example
现在加最后一样,就是oauth2,现在很多网站都有对应的移动版本,那么移动端访问服务端的服务怎么控制权限,我知道的主要是两种方法,第一是模拟浏览器,访问服务的时候会生成session,之后在移动端缓存 ...
- Orchard源码:Logging
试着用markdown写些东西.貌似博客园支持的还有问题,代码片段显示错位,还得另外上传图片.还是用普通方法写写随笔好了. Logging相对也是比较松耦合的模块,可以随时提取出来用在自己的项目中.其 ...
- jQuery Mobile笔记
1.获取jQuery mobile 文件,访问jQuerymobile网站下载 (貌似使用jquery mobile后,jquery会自动在网页中添加一些class类,第一次知道的我是被吓呆的!!) ...
- Sass学习之路(1)——Sass简介
Sass是CSS的一种预处理器语言,类似的语言还有Less,Stylus等. 那么什么是CSS预处理器? CSS 预处理器定义了一种新的语言,其基本思想是,用一种专门的编程语言,为 CSS 增加了一些 ...
- 实验12:Problem D: 判断两个圆之间的关系
Home Web Board ProblemSet Standing Status Statistics Problem D: 判断两个圆之间的关系 Problem D: 判断两个圆之间的关系 T ...
- IOS沙盒
可以先在程序打印沙盒路径: NSLog(@"路径%@",NSHomeDirectory()); ------------------------------------------ ...
- 简明 Vim 练级攻略(转)
原文:http://coolshell.cn/articles/5426.html vim的学习曲线相当的大(参看各种文本编辑器的学习曲线),所以,如果你一开始看到的是一大堆VIM的命令分类,你一定会 ...