《linux下智能DNS配置过程》由会员分享,可在线阅读,更多相关《linux下智能DNS配置过程(11页珍藏版)》请在金锄头文库上搜索。
1、linux 下智能 DNS 配置过程1 / 11linux 下智能 DNS 配置过程 摘要:对于配置智能 DNS,主要用途为:1、解决网通与电信问题 2、实现区域规划(不同区域访问各自最近的服务器),下面以解决网通与电信连接问题的配置。至于实现 2 的功能,只需稍加更改即可。 一、DNS 服务器安装1、 软件列表BIND 9.3.2ftp:/ftp.isc.org/isc/bind9/9.3.2/bind-9.3.2.tar.gzftp:/ftp.isc.org/isc/bind9/9.4.0a6/bind-9.4.0a6.tar.gz2、 安装 BIND 9安装 BIND9:# tar zx
2、vf bind-9.3.2.tar.gz# cd bind-9.3.2# ./configure -prefix=/usr/local/named -disable-ipv6# make & make install建立 BIND 用户:# groupadd bind# useradd -g bind -d /usr/local/named -s /sbin/nologin bind创建配置文件目录:# mkdir p /usr/local/named/etc# chown bind:bind /usr/local/named/etc# chmod 700 /usr/local/named/e
3、tc二、named.conf 的配置创建主要的配置文件:# vi /usr/local/named/etc/named.conf=named.conf=linux 下智能 DNS 配置过程2 / 11acl trust-lan 127.0.0.1/8; 192.168.0.0/16;options directory /usr/local/named/etc/;pid-file /var/run/named/named.pid;version 0.0.0;datasize 40M;allow-transfer trust-lan;recursion yes;allow-notify trust
4、-lan;allow-recursion trust-lan;auth-nxdomain no;forwarders 211.162.106.9;211.162.106.254;logging channel warning file /var/log/named/dns_warnings versions 3 size 1240k;severity warning;print-category yes;linux 下智能 DNS 配置过程3 / 11print-severity yes;print-time yes;channel general_dns file /var/log/name
5、d/dns_logs versions 3 size 1240k;severity info;print-category yes;print-severity yes;print-time yes;category default warning; ;category queries general_dns; ;zone . type hint;file named.root;acl CNC 58.16.0.0/16;58.17.0.0/17;58.17.128.0/17;58.18.0.0/16;58.19.0.0/16;58.20.0.0/16;58.21.0.0/16;linux 下智
6、能 DNS 配置过程4 / 11注:这些根据情况输入 IP 地址段;view view_cnc match-clients CNC; ;zone . type hint;file named.root;zone 0.0.127.IN-ADDR.ARPA type master;file localhost.rev;include master/cnc.def;view view_any match-clients any; ;zone . type hint;file named.root;zone 0.0.127.IN-ADDR.ARPA type master;file localhost
7、.rev;include master/telecom.def;linux 下智能 DNS 配置过程5 / 11;添加完成后,保存。三、更新根区文件:# cd /usr/local/named/etc/# wget ftp:/ftp.internic.org/domain/named.root创建 PID 和日志文件:# mkdir /var/run/named/# chmod 777 /var/run/named/# chown bind:bind /var/run/named/# mkdir /var/log/named/# touch /var/log/named/dns_warning
8、s# touch /var/log/named/dns_logs# chown bind:bind /var/log/named/*# mkdir master# touch master/cnc.def# touch master/telecom.def生成 rndc-key:# cd /usr/local/named/etc/# ./sbin/rndc-confgen rndc.conf把 rndc.conf 中:# Use with the following in named.conf, adjusting the allow list as needed:后面以的部分加到/usr/l
9、ocal/named/etc/named.conf 中并去掉注释运行测试:# /usr/local/named/sbin/named -gc /usr/local/named/etc/named.conf &状态检查:linux 下智能 DNS 配置过程6 / 11# /usr/local/named/sbin/rndc status四、建立启动脚本:# vi /etc/init.d/named= named.sh=#!/bin/bash# named a network name service.# chkconfig: 545 35 75# description: a name serv
10、er#if id -u -ne 0 thenecho ERROR:For bind to port 53,must run as root.exit 1ficase instart)if -x /usr/local/named/sbin/named ; then/usr/local/named/sbin/named -u bind -c /usr/local/named/etc/named.conf & echo . & echo BIND9 server started.fi;stop)linux 下智能 DNS 配置过程7 / 11kill cat /var/run/named/pid &
11、 echo . & echo BIND9 server stopped.;restart)echo .echo Restart BIND9 serverstopsleep 10start;*)echo start | stop | restart;esac=named.sh=# chmod 755 /etc/init.d/named# chown root:root /etc/init.d/named# chkconfig -add named# chkconfig named on五、添加一个 NS在域名的管理网站上,设定 NS 服务器为你安装的 DNS六、添加一个域名 # cd /usr/
12、local/named/etc/master# mkdir cnc# mkdir telecom# vi cnc.deflinux 下智能 DNS 配置过程8 / 11添加zone type master;file master/cnc/;# vi telecom.def添加zone type master;file master/telecom/;添加网通的解析,解析到的 IP 为 61.45.55.78#vi cnc/添加$TTL 3600$ORIGIN . IN SOA . .(2005121013 ;Serial3600 ; Refresh ( seconds )900 ; Ret
13、ry ( seconds )68400 ; Expire ( seconds )15 );Minimum TTL for Zone ( seconds ); IN NS . IN A 211.162.106.9linux 下智能 DNS 配置过程9 / 11www IN A 211.162.106.9;end添加电信的解析,解析到的 IP 为 210.75.1.178#vi telecom/添加$TTL 3600$ORIGIN . IN SOA . .(2005121013 ;Serial3600 ; Refresh ( seconds )900 ; Retry ( seconds )6840
14、0 ; Expire ( seconds )15 );Minimum TTL for Zone ( seconds ); IN NS . IN A 211.162.106.254www IN A 211.162.106.254;end#/usr/local/named/sbin/rndc reloadOK,到此你的 DNS 服务器就算是跑起来了。试一下分别用网通和电信的线路 ping 一下吧.附:获取 IP 地址范围方法:1、 利用 shell 程序获取 IP 地址段#!/bin/shlinux 下智能 DNS 配置过程10 / 11FILE=/root/study/apnic/ip_apnicrm -f $FILEwget http:/ -O $FILEgrep apnic|CN|ipv4| $FILE | cut -f 4,5 -d|sed -e s/|/ /g | while read ip cntdoecho $ip:$cntmask=$(cat NETNAME=whois $ | sed -e /./H;$!d;