数据库连接方法
[root@gd02-qa-plxt2-nodomain /]# mysql -u vipdns -pvipdns -h 10.0.3.99 mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | pdns | +--------------------+ 2 rows in set (0.00 sec)
注:
-u 指定用户名 (vipdns)
-p 指定密码 (vipdns)
-h 指定主机 (10.0.3.99)
默认端口 3306
表信息
mysql> show tables; +--------------------+ | Tables_in_pdns | +--------------------+ | cryptokeys | | domainmetadata | | domains | | perm_items | | perm_templ | | perm_templ_items | | records | | supermasters | | tsigkeys | | users | | zone_templ | | zone_templ_records | | zones | +--------------------+ 13 rows in set (0.00 sec)
重点关注: domain 表 records 表
domain 表结构
mysql> desc domains; +-----------------+--------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +-----------------+--------------+------+-----+---------+----------------+ | id | int(11) | NO | PRI | NULL | auto_increment | | name | varchar(255) | NO | UNI | NULL | | | master | varchar(128) | YES | | NULL | | | last_check | int(11) | YES | | NULL | | | type | varchar(6) | NO | | NULL | | | notified_serial | int(11) | YES | | NULL | | | account | varchar(40) | YES | | NULL | | +-----------------+--------------+------+-----+---------+----------------+ 7 rows in set (0.01 sec)
当前 domains 表中数据
mysql> select * from domains; +----+---------------------+--------+------------+--------+-----------------+---------+ | id | name | master | last_check | type | notified_serial | account | +----+---------------------+--------+------------+--------+-----------------+---------+ | 1 | vclound.com | NULL | NULL | MASTER | NULL | NULL | | 2 | 3.0.10.in-addr.arpa | NULL | NULL | MASTER | NULL | NULL | +----+---------------------+--------+------------+--------+-----------------+---------+ 2 rows in set (0.00 sec)
说明:
id - 主键 name - 域名(当前已添加两个), 先关注 vclound.com master - 未知 last_check - 未知 type - 是否主域服务器 (通常只有一个 DNS 情况都是 MASTER) notified_serial - 修改版本信息 account - 未知
添加 163.com 域名 , 调用 sql 例
insert into pdns.domains (name, type) values ( ‘163.com‘, ‘MASTER‘);
更新, 删除, (略)
records 表结构
+-------------+--------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +-------------+--------------+------+-----+---------+----------------+ | id | int(11) | NO | PRI | NULL | auto_increment | | domain_id | int(11) | YES | MUL | NULL | | | name | varchar(255) | YES | MUL | NULL | | | type | varchar(10) | YES | | NULL | | | content | mediumtext | YES | | NULL | | | ttl | int(11) | YES | | NULL | | | prio | int(11) | YES | | NULL | | | change_date | int(11) | YES | | NULL | | | ordername | varchar(255) | YES | | NULL | | | auth | tinyint(1) | YES | | NULL | | +-------------+--------------+------+-----+---------+----------------+ 10 rows in set (0.00 sec)
注: records.domain_id 是 domains 的外键
表说明
id - 主键 domain_id - domains 表(id) 的外键 name - 域名(vclound.com), 正向解析(ddns.vcloudn.com), 反向解析的主机名(105.3.0.10.in-addr.arpa) type - 定义 name 字段的说明, 如 (SOA [dns 域名) A [正向解析] PTR [反向解析], MX [邮件服务器], CNAME [主机别名] 字段必须大写 content - 定义 name 所对应的 DNS 解析 [对于 type 为 SOA 时, 比较复杂, 不过可参考当前变量值作为固定值] ttl - 缓存时候, 可作为固定值 prio - 优先级别, 忽略 change_date - 时间戳 ordername - 忽略 auth - 未知道
当前表单中的正向解析数据
mysql> select id, name, type, content, ttl, change_date from records where domain_id=1; +----+---------------------+------+----------------------------------------------------------------------+-------+-------------+ | id | name | type | content | ttl | change_date | +----+---------------------+------+----------------------------------------------------------------------+-------+-------------+ | 1 | vclound.com | SOA | ddns.vclound.com ddns.vclound.com 2014013003 28800 7200 604800 86400 | 86400 | 1391015078 | | 4 | pdnsweb.vclound.com | A | 10.0.3.103 | 86400 | 1391015359 | | 5 | pdns.vclound.com | A | 10.0.3.99 | 86400 | 1391015379 | | 6 | pdnsdb.vclound.com | A | 10.0.3.99 | 86400 | 1391015391 | +----+---------------------+------+----------------------------------------------------------------------+-------+-------------+
反向解析数据
mysql> select id, name, type, content, ttl, change_date from records where domain_id=2;
+----+-------------------------+------+----------------------------------------------------------------------+-------+-------------+
| id | name | type | content | ttl | change_date |
+----+-------------------------+------+----------------------------------------------------------------------+-------+-------------+
| 2 | 3.0.10.in-addr.arpa | SOA | ddns.vclound.com ddns.vclound.com 2014013002 28800 7200 604800 86400 | 86400 | 1391015099 |
| 3 | 99.3.0.10.in-addr.arpa | PTR | pdnsdb.vclound.com | 86400 | 1391015270 |
| 7 | 103.3.0.10.in-addr.arpa | PTR | pdnsweb.vcloud.com | 86400 | 1391018671 |
+----+-------------------------+------+----------------------------------------------------------------------+-------+-------------+
3 rows in set (0.00 sec)
模拟添加 163.com 的正向解析方法
这个是域名记录
insert into records (name, type, content, ttl, change_date) values (‘163.com, ‘SOA‘, ‘dns.163.com dns.163.com 2014013002 28800 7200 604800 86400‘, ‘86400‘);
这个是主机名记录
insert into records (name, type, content, ttl, change_date) values (‘dns.163.com, ‘A‘, ‘192.168.0.1‘, ‘86400‘); insert into records (name, type, content, ttl, change_date) values (‘www.163.com, ‘A‘, ‘192.168.0.2‘, ‘86400‘);
这样就可以增加两个主机记录了
反向同理, 切记域名为 0.168.192.in-addr.arpa 即可
验证 dns 方法
/etc/resolv.conf
nameserver 10.0.3.99 <-必须指向他
[root@gd02-qa-plxt2-nodomain /]# nslookup vclound.com Server: 10.0.3.99 Address: 10.0.3.99#53 *** Can‘t find vclound.com: No answer [root@gd02-qa-plxt2-nodomain /]# nslookup pdnsweb.vclound.com Server: 10.0.3.99 Address: 10.0.3.99#53 Name: pdnsweb.vclound.com Address: 10.0.3.103 [root@gd02-qa-plxt2-nodomain /]# nslookup pdnsdb.vclound.com Server: 10.0.3.99 Address: 10.0.3.99#53 Name: pdnsdb.vclound.com Address: 10.0.3.99
参考, 上述例子, 注: 不可以直接解析域名
参考反向解析例子
[root@gd02-qa-plxt2-nodomain /]# nslookup 10.0.3.99 Server: 10.0.3.99 Address: 10.0.3.99#53 99.3.0.10.in-addr.arpa name = pdnsdb.vclound.com. [root@gd02-qa-plxt2-nodomain /]# nslookup 10.0.3.103 Server: 10.0.3.99 Address: 10.0.3.99#53 103.3.0.10.in-addr.arpa name = pdnsweb.vcloud.com.