安装dns:bind{Berkeley Internet Name Domain}
规划:dns服务器ip192.168.0.15
解析2个地址www.kvm.com 解析到192.168.0.100 #192.168.0.100 虚拟的只要能解析出来即可实际环境当中肯定不行得是真正的服务器ip
www.xen.com 解析到 192.168.0.200 #同上
[root@kvm003 ~]# cat /etc/redhat-release #查看系统版本 CentOS release 6.6 (Final) [root@kvm003 ~]# yum install bind bind-chroot -y #安装需要的软件 bind-chroot是改变bind的工作目录,为了安全 [root@kvm003 ~]# rpm -ql bind #查看bind安装了那些文件 [root@kvm003 ~]# rpm -ql bind-chroot #查看bind-chroot安装那些文件 /var/named/chroot /var/named/chroot/dev /var/named/chroot/dev/null /var/named/chroot/dev/random /var/named/chroot/dev/zero /var/named/chroot/etc #主配置文件,安炸了bind-chroot配置文件就在这了 装完没有配置文件启动后会把/ect/named.conf 挂载到这个目录下 /var/named/chroot/etc/localtime /var/named/chroot/etc/named /var/named/chroot/etc/named.conf /var/named/chroot/etc/pki /var/named/chroot/etc/pki/dnssec-keys /var/named/chroot/usr /var/named/chroot/usr/lib64 /var/named/chroot/usr/lib64/bind /var/named/chroot/var /var/named/chroot/var/log /var/named/chroot/var/named /var/named/chroot/var/run /var/named/chroot/var/run/named /var/named/chroot/var/tmp #启动bind [root@kvm003 etc]# /etc/init.d/named start Generating /etc/rndc.key:[ OK ] Starting named: [ OK ] #查看侦听端口 [root@kvm003 etc]# ss -antlp |grep :53 LISTEN 0 3 ::1:53 :::* users:(("named",3763,21)) LISTEN 0 3 127.0.0.1:53 *:* users:(("named",3763,20)) #查看 [root@kvm003 etc]# pwd #注意路径 /var/named/chroot/etc [root@kvm003 etc]# ls localtime named.conf named.rfc1912.zones pki #配置文件named.conf named named.iscdlv.key named.root.key rndc.key
开始配置
[root@kvm003 etc]# pwd /var/named/chroot/etc [root@kvm003 etc]# ls localtime named.conf named.rfc1912.zones pki named named.iscdlv.key named.root.key rndc.key [root@kvm003 etc]# cp named.conf named.conf.bak #配置之前先备份 [root@kvm003 etc]# vim named.conf #编辑主配置文件 修改如下 # listen-on port 53 { 127.0.0.1; }; #注视掉表示侦听所有ip的53 allow-query { any; }; #允许谁查询 # [root@kvm003 etc]# cp named.rfc1912.zones named.rfc1912.zones.bak
配置区域文件
[root@kvm003 etc]# pwd /var/named/chroot/etc #注意路径 [root@kvm003 etc]# ls localtime named.conf.bak named.rfc1912.zones.bak rndc.key named named.iscdlv.key named.root.key named.conf named.rfc1912.zones pki [root@kvm003 etc]# vim named.rfc1912.zones 定义区域配置文件 zone "kvm.com" IN { #kvm.com 正向区域 type master; file "kvm.com.zone"; allow-update { none; }; }; zone "xen.com" IN { #xen.com 正想区域 type master; file "xen.com.zone"; allow-update { none; }; }; zone "0.168.192.in-addr.arpa" IN { #对应的反向解析 type master; file "kvm.com"; allow-update { none; }; };
复制区域文件
[root@kvm003 etc]# cd /var/named/chroot/var/named/ [root@kvm003 named]# cp -p named.localhost kvm.com.zone #注意权限要加-p [root@kvm003 named]# cp -p named.localhost xen.com.zone [root@kvm003 named]# cp -p named.loopback kvm.com 因为2个域名都是192.168.0 网段的所以没必要 查看 [root@kvm003 named]# ll total 48 drwxr-x---. 6 root named 4096 Jan 23 00:54 chroot drwxrwx---. 2 named named 4096 Jan 23 00:58 data drwxrwx---. 2 named named 4096 Jan 23 00:59 dynamic -rw-r-----. 1 root named 179 Jan 23 01:29 kvm.com -rw-r-----. 1 root named 199 Jan 23 01:30 kvm.com.zone -rw-r-----. 1 root named 2075 Apr 23 2014 named.ca -rw-r-----. 1 root named 152 Dec 15 2009 named.empty -rw-r-----. 1 root named 152 Jun 21 2007 named.localhost -rw-r-----. 1 root named 168 Dec 15 2009 named.loopback drwxrwx---. 2 named named 4096 Dec 11 22:25 slaves -rw-r-----. 1 root named 199 Jan 23 01:30 xen.com.zone
修改区域文件属性
[root@kvm003 named]# vim kvm.com.zone #编辑正想解析区域文键 $TTL 1D @ IN SOA @ jjwei886.gmail.com. ( 0 ; serial 1D ; refresh 1H ; retry 1W ; expire 3H ) ; minimum NS kvm.com. #注意这里面域名后面的点 A 192.168.0.100 www A 192.168.0.100 mail A 192.168.0.100 [root@kvm003 named]# vim xen.com.zone ## $TTL 1D @ IN SOA @ [email protected]. ( 0 ; serial 1D ; refresh 1H ; retry 1W ; expire 3H ) ; minimum NS xen.com. A 192.168.0.200 www A 192.168.0.200 mail A 192.168.0.200 #反向解析 [root@kvm003 named]# vim kvm.com ## $TTL 1D @ IN SOA @ rname.invalid. ( 0 ; serial 1D ; refresh 1H ; retry 1W ; expire 3H ) ; minimum NS kvm.com. 100 PTR www.kvm.com. 100 PTR mail.kvm.com. 200 PTR www.xen.com. 200 PTR mail.xen.com.
安装测试工具
[root@kvm003 named]# yum install bind-utils #安装解析工具 [root@kvm003 named]# rpm -ql bind-utils #查看都安装了那些工具 /usr/bin/dig #常用 /usr/bin/host #长用 /usr/bin/nslookup #常用 /usr/bin/nsupdate /usr/share/man/man1/dig.1.gz /usr/share/man/man1/host.1.gz /usr/share/man/man1/nslookup.1.gz /usr/share/man/man1/nsupdate.1.gz
重启named
[root@kvm003 named]# /etc/init.d/named restart #重启 Stopping named: .umount: /var/named/chroot/var/named: device is busy. (In some cases useful info about processes that use the device is found by lsof(8) or fuser(1)) [ OK ] Starting named: [ OK ] #退出到家目录在重启,说设备忙 [root@kvm003 named]# cd [root@kvm003 ~]# /etc/init.d/named restart Stopping named: .[ OK ] Starting named: [ OK ]
测试
#首先查看你的ip是不是192.168.0.15,DNS是不是192.168.0.15 [root@kvm003 ~]# ifconfig eth0 #查看ip eth0 Link encap:Ethernet HWaddr 52:54:00:A1:7C:F9 inet addr:192.168.0.15 Bcast:192.168.0.255 Mask:255.255.255.0 inet6 addr: fe80::5054:ff:fea1:7cf9/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:114089 errors:0 dropped:0 overruns:0 frame:0 TX packets:54382 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:141216506 (134.6 MiB) TX bytes:3765221 (3.5 MiB) [root@kvm003 ~]# cat /etc/resolv.conf #查看DNS nameserver 192.168.0.15 #测试 [root@kvm003 ~]# dig www.kvm.com # ; <<>> DiG 9.8.2rc1-RedHat-9.8.2-0.30.rc1.el6_6.1 <<>> www.kvm.com ;; global options: +cmd ;; Got answer: ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 13080 #状态为 status: NOERROR 就表示没错 ;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 1, ADDITIONAL: 1 ;; QUESTION SECTION: ;www.kvm.com. IN A ;; ANSWER SECTION: www.kvm.com. 86400 IN A 192.168.0.100 #www.kvm.com解析对应的IP ;; AUTHORITY SECTION: kvm.com. 86400 IN NS kvm.com. ;; ADDITIONAL SECTION: kvm.com. 86400 IN A 192.168.0.100 ;; Query time: 0 msec ;; SERVER: 192.168.0.15#53(192.168.0.15) ;; WHEN: Fri Jan 23 01:55:54 2015 ;; MSG SIZE rcvd: 75 # [root@kvm003 ~]# dig www.xen.com ; <<>> DiG 9.8.2rc1-RedHat-9.8.2-0.30.rc1.el6_6.1 <<>> www.xen.com ;; global options: +cmd ;; Got answer: ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 21607 #### ;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 1, ADDITIONAL: 1 ;; QUESTION SECTION: ;www.xen.com. IN A ;; ANSWER SECTION: www.xen.com. 86400 IN A 192.168.0.200 ## ;; AUTHORITY SECTION: xen.com. 86400 IN NS xen.com. ;; ADDITIONAL SECTION: xen.com. 86400 IN A 192.168.0.200 ;; Query time: 0 msec ;; SERVER: 192.168.0.15#53(192.168.0.15) ;; WHEN: Fri Jan 23 01:57:18 2015 ;; MSG SIZE rcvd: 75 反向解析 [root@kvm003 ~]# dig -x 192.168.0.100 #反向解析 ; <<>> DiG 9.8.2rc1-RedHat-9.8.2-0.30.rc1.el6_6.1 <<>> -x 192.168.0.100 ;; global options: +cmd ;; Got answer: ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 35321 # ;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 1, ADDITIONAL: 1 ;; QUESTION SECTION: ;100.0.168.192.in-addr.arpa. IN PTR ;; ANSWER SECTION: 100.0.168.192.in-addr.arpa. 86400 IN PTR www.kvm.com. # ;; AUTHORITY SECTION: 0.168.192.in-addr.arpa. 86400 IN NS kvm.com. # ;; ADDITIONAL SECTION: kvm.com. 86400 IN A 192.168.0.100 ;; Query time: 0 msec ;; SERVER: 192.168.0.15#53(192.168.0.15) ;; WHEN: Fri Jan 23 02:26:40 2015 ;; MSG SIZE rcvd: 99 ## [root@kvm003 ~]# dig -x 192.168.0.200 # ; <<>> DiG 9.8.2rc1-RedHat-9.8.2-0.30.rc1.el6_6.1 <<>> -x 192.168.0.200 ;; global options: +cmd ;; Got answer: ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 6367 ### ;; flags: qr aa rd ra; QUERY: 1, ANSWER: 2, AUTHORITY: 1, ADDITIONAL: 1 ;; QUESTION SECTION: ;200.0.168.192.in-addr.arpa. IN PTR ;; ANSWER SECTION: 200.0.168.192.in-addr.arpa. 86400 IN PTR mail.xen.com. # 200.0.168.192.in-addr.arpa. 86400 IN PTR www.xen.com. # ;; AUTHORITY SECTION: 0.168.192.in-addr.arpa. 86400 IN NS kvm.com. ;; ADDITIONAL SECTION: kvm.com. 86400 IN A 192.168.0.100 ;; Query time: 0 msec ;; SERVER: 192.168.0.15#53(192.168.0.15) ;; WHEN: Fri Jan 23 02:27:23 2015 ;; MSG SIZE rcvd: 122
BIND还有高速缓存,主从复制,负载均衡,等等,。。。有时间在完善