Chinaunix首页 | 论坛 | 博客
  • 博客访问: 21098
  • 博文数量: 7
  • 博客积分: 207
  • 博客等级: 入伍新兵
  • 技术积分: 110
  • 用 户 组: 普通用户
  • 注册时间: 2011-03-23 16:18
文章分类
文章存档

2012年(1)

2011年(6)

我的朋友

分类: LINUX

2011-03-23 16:54:50

软件列表:

BIND 9.3.2:

ftp://ftp.isc.org/isc/bind9/9.3.2/bind-9.3.2.tar.gz

ftp://ftp.isc.org/isc/bind9/9.4.0a6/bind-9.4.0a6.tar.gz

mysql-bind-0-1.


1、一个只缓存名字服务器

下列配置样例合适用于一个只缓存名字服务器,用于一个公司的内部客户端。通过使用

allow-query 选项,所有外来客户端的请求都被拒绝。另外一个选择是,使用合适的防火墙规

则也可以取得同样的效果。

// Two corporate subnets we wish to allow queries from.

acl corpnets { 192.168.4.0/24; 192.168.7.0/24; };

options {

directory "/etc/namedb"; // Working directory

allow-query { corpnets; };

};

// Provide a reverse mapping for the loopback address 127.0.0.1

zone "0.0.127.in-addr.arpa" {

type master;

file "localhost.rev";

notify no;

};
2、一个只权威名字服务器

这个样例配置是给只作权威服务器的,在这里服务器作“example.com”的主服务器和其子域

“eng.exmaple.com”的辅服务器。

options {

directory "/etc/namedb"; // Working directory

allow-query-cache { none; }; // Do not allow access to cache

allow-query { any; }; // This is the default

recursion no; // Do not provide recursive service

};



// Provide a reverse mapping for the loopback address 127.0.0.1

zone "0.0.127.in-addr.arpa" {

type master;

file "localhost.rev";

notify no;

};

// We are the master server for example.com

zone "example.com" {

type master;

file "example.com.db";

// IP addresses of slave servers allowed to transfer example.com

allow-transfer {

192.168.4.14;

192.168.5.53;

};

};

// We are a slave server for eng.example.com

zone "eng.example.com" {

type slave;

file "eng.example.com.bk";

// IP address of eng.example.com master server

masters { 192.168.4.12; };

};
3、Bind智能解析(包括主辅同步)
3.1下载所需软件

# wget ftp://ftp.isc.org/isc/bind9/9.3.2/bind-9.3.2.tar.gz
3.2安装BIND 9

安装BIND9:

# tar zxvf bind-9.3.2.tar.gz

# cd bind-9.3.2

# ./configure --prefix=/usr/local/named --disable-ipv6 --enable-threads

--enable-threads 开启多线程,更多选项可使用./configure --help参数查看

# make && make install
3.3配置BIND9

建立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/etc

生成rndc控制命令的key文件:

# /usr/local/named/sbin/rndc-confgen > /usr/local/named/etc/rndc.conf

# cd /usr/local/named/etc

# tail -10 rndc.conf | head -9 | sed s/# \ //g > named.conf

编辑named.conf主配置文件:

# vi /usr/local/named/etc/named.conf

# # # # # # # # # # # # # # # named.conf# # # # # # # # # # # # # #

acl "trust-lan" { any; };

options {

directory "/usr/local/named/etc/"; //bind文件的配置目录

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

version "0.0.0";

allow-query { any; };

};

logging {

channel warning { file "/var/log/named/dns_warnings" versions 3 size 1240k;

severity warning;

print-category yes;

print-severity yes;

print-time yes;

};

channel general_dns

{ file "/var/log/named/dns_logs" versions 3 size 1240k;

severity info;

print-category yes;

print-severity yes;

print-time yes;

};

category default { warning; };

category queries { general_dns; };

};

include "acl/telecom.acl"; //include电信ip段列表

view "view_telecom" {

match-clients { telecom; };

zone "." {

type hint;

file "named.root";

};

zone "localhost" IN {

type master;

file "localhost.zone";

allow-update { none; };

};

zone "0.0.127.IN-ADDR.ARPA" {

type master;

file "localhost.rev";

};

include "master/telecom.def";

};

view "view_any" {

match-clients { any; };

zone "." {

type hint;

file "named.root";

};

zone "localhost" IN {

type master;

file "localhost.zone";

allow-update { none; };

};

zone "0.0.127.IN-ADDR.ARPA" {

type master;

file "localhost.rev";

};

include "master/cnc.def";

};

# # # # # # # # # # # end# # # # # # # # #

创建acl列表:

# mkdir acl

# vi telecom.acl

acl "telecom" {

58.154.0.0/15;

58.192.0.0/12;

59.64.0.0/12;

116.13.0.0/16;

收集到的网通的地址段

};

创建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_warnings

# touch /var/log/named/dns_logs

# chown bind:bind /var/log/named

  

  添加 mysqldb_init();

  找到

  

  

  添加 mysqldb_clear();

loading zone: creating database: failure错误处理

如果出现这个问题,那说明bind sdb驱动和mysql链接出现了问题,诸如密码错误,dns没有建立,引用/tmp/mysql.sock错误等等.这个问题出现之后,你需要在mysqldb.c中加入一些调试信息:

在mysqldb.c的db_connect函数中修改:

引用

if (mysql_real_connect ( &dbi->conn, dbi->host, dbi->user, dbi->passwd, dbi->database, 0, NULL, 0 ))

{

fprintf(stderr,"\nconnect successfully .............. \n");

return (ISC_R_SUCCESS);

}

else

{

fprintf(stderr,"\nconnect fail:%s , host %s,user %s,passwd %s,db %s,port %d ...................\n",mysql_error(&dbi->conn),dbi->host,dbi->user,dbi->passwd,dbi->database);

return (ISC_R_FAILURE);

}

这样方便得到出错信息.然后根据出错信息调试mysql,使bind sdb能成功链接mysql.
4.5编译安装、配置bind 

# ./configure --prefix=/usr/local/named --enable-threads #--enable-threads开启多线程处理能力

# make

# make install

# cd /usr/local/named

# mkdir etc 建立etc目录

# sbin/rndc-confgen > etc/rndc.conf 生成rndc控制命令的key文件

生成rndc key

# cd etc

# tail -10 rndc.conf | head -9 | sed s/#\ //g > named.conf 从rndc.conf文件中提取named.conf用的key自动在/usr/local/named/etc 生成named,conf文件

建立localhost.zone文件

# vi localhost.zone

$TTL 86400

$ORIGIN localhost.

@ 1D IN SOA @ root (

   42 ; serial (d. adams)

   3H ; refresh

   15M ; retry

   1W ; expiry

   1D ) ; minimum

1D IN NS @

1D IN A 127.0.0.1

建立named.local文件

# vi named.local

$TTL 86400

@ IN SOA localhost. root.localhost. (

   1997022700 ; Serial

     28800 ; Refresh

   14400 ; Retry

   3600000 ; Expire

   86400 ) ; Minimum

IN NS localhost.

1 IN PTR localhost.

dig命令直接生成named.root文件

# dig > named.root

配置 named.conf

增加如下内容:

controls {

  inet 127.0.0.1 port 953

  * directive below. Previous versions of BIND always asked

  * questions using port 53, but BIND 9.31 uses an unprivileged

  * port by default.

  */

  // query-source address * port 53;

  24,9

  };

  //

 // a caching only nameserver config

  //

  zone "." IN {

  type hint;

  file "named.root";

  };

  zone "localhost" IN {

  type master;

  file "localhost.zone";

  allow-update { none; };

  };

  zone "0.0.127.in-addr.arpa" IN {

  type master;

  file "named.local";

  allow-update { none; };

  };

  zone "mydomain.com" {

  type master;

  database "mysqldb dnsdb mydomain localhost root passwd"; 配置你的数据库名,表名,MYSQL主机,MYSQL用户,MYSQL密码

  };

  zone "19.202.220.in-addr.arpa" {

  type master;

  database "mysqldb dnsdb ptr localhost root passwd"; 配置你的数据库名,表名,MYSQL主机,MYSQL用户,MYSQL密码

  };

BIND安装完成!
4.6建立bind数据库

我是用MYSQLADMIN来建立数据库的和倒数据的,APACHE下安装MYSQLADMIN我这里就不详细讲了。

正向解析数据库mydomain表结构

>CREATE TABLE mydomain (

>name varchar(255) default NULL,

>ttl int(11) default NULL,

>rdtype varchar(255) default NULL,

>rdata varchar(255) default NULL

>) TYPE=MyISAM;

以下是正向解析示范可以直接倒入

>INSERT INTO mydomain VALUES ('mydomain.com', 259200, 'SOA', 'mydomain.com. 200309181 28800 7200 86400 28800');

>INSERT INTO mydomain VALUES ('mydomain.com', 259200, 'NS', 'ns0.mydomain.com.');

>INSERT INTO mydomain VALUES ('mydomain.com', 259200, 'NS', 'ns1.mydomain.com.');

>INSERT INTO mydomain VALUES ('mydomain.com', 259200, 'MX', '10 mail.mydomain.com.');

>INSERT INTO mydomain VALUES ('w0.mydomain.com', 259200, 'A', '192.168.1.1');

>INSERT INTO mydomain VALUES ('w1.mydomain.com', 259200, 'A', '192.168.1.2');

>INSERT INTO mydomain VALUES ('mydomain.com', 259200, 'Cname', 'w0.mydomain.com.');

>INSERT INTO mydomain VALUES ('mail.mydomain.com', 259200, 'Cname', 'w0.mydomain.com.');

>INSERT INTO mydomain VALUES ('ns0.mydomain.com', 259200, 'Cname', 'w0.mydomain.com.'

>INSERT INTO mydomain VALUES ('ns1.mydomain.com', 259200, 'Cname', 'w1.mydomain.com.');

>INSERT INTO mydomain VALUES ('', 259200, 'Cname', 'w0.mydomain.com.');

>INSERT INTO mydomain VALUES ('ftp.mydomain.com', 259200, 'Cname', 'w0.mydomain.com.');

反向解析数据库ptr表结构

>CREATE TABLE ptr (

>name varchar(255) default NULL,

>ttl int(11) default NULL,

>rdtype varchar(255) default NULL,

>rdata varchar(255) default NULL

>) TYPE=MyISAM;

以下是反向解析示范可以直接倒入

>INSERT INTO `ptr` VALUES ('19.202.220.in-addr.arpa', 17600, 'SOA', 'mydomain.com. 200309181 28800 7200 86400 28800');

>INSERT INTO `ptr` VALUES ('19.202.220.in-addr.arpa', 17600, 'NS', 'ns0.mydomain.com.');

>INSERT INTO `ptr` VALUES ('19.202.220.in-addr.arpa', 17600, 'NS', 'ns1.mydomain.com.');

>INSERT INTO `ptr` VALUES ('82.19.202.220.in-addr.arpa', 17600, 'PTR', 'mail.mydomain.');

  --------------------------------------------------------------------------------数据库建立完成

启动你的BIND 测试BIND是否能正常工作

# /usr/local/named/sbin/named -c /usr/local/named/etc/named.conf &

然后在你WINDOWS机器上将这个配置了BIND的IP设置为DNS然后运行nslookup测试

如果出现证明反向解析正常

Default Server: mail.mydomain

Address: 220.202.19.2

>

如果PING w0.mydomain.com

解析地址为192.168.1.1 证明正向工作正常

结束语:

BIND + MYSQL 在增加A记录 MX记录 PTR记录都不需要从新启动BIND,每增加一个正向的解析域名都必须在named.conf正增加如下内容

  zone "youname.com" {

  type master;

  database "mysqldb dnsdb mydomain localhost root passwd"; 配置你的数据库名,表名,MYSQL主机,MYSQL用户,MYSQL密码

};
阅读(1715) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~