一、概述:
DNS:Domain Name System,域名系统。internet作为域名和IP地址相互映射的一个分布式数据库,能够使用户 更方便的访问互联网,而不用去记住IP地址。
通过主机名,最终得到该主机名对应的IP地址的过程叫做域名解析(或主机解析)。DNS运行在UDP协议,监听53号端口。
通常Internet主机域名全球唯一,一般主要结构为:
DNS解析类型: FQDN(完全合格域名)—>IP 正向解析 FQDN<—IP 反向解析
linux下DNS的名称解析库:/etc/named 文本文件:每一行称作一个资源记录 资源记录类型: FQDN—>IPv4 :A FQDN—>IPv6 :AAAA Domain –> DNS Server :NS (Name Server) Domain—>Master Dns : SOA (start of authority) FQDN—>FQDN :CNAME (canonical name) IP—>FQDN : PTR (pointer) Domain –>MX (Mail exchange),有优先级(0-99),数字越小优先级越高 IP—>FQDN : .inaddr.arpa
二、建立DNS正向解析:
1.安装bind包:yum install –y bind;
2.rpm –qc bind 查看bind安装生成的文件;
[[email protected] ~]# rpm -qc bind /etc/logrotate.d/named /etc/named.conf /etc/named.iscdlv.key /etc/named.rfc1912.zones /etc/named.root.key /etc/rndc.conf /etc/rndc.key /etc/sysconfig/named /var/named/named.ca /var/named/named.empty /var/named/named.localhost /var/named/named.loopback
3.修改主配置文件/etc/named.conf;
// listen-on port 53 { 127.0.0.1; }; // listen-on-v6 port 53 { ::1; }; // allow-query { localhost; };
这三行配置文件前面加//
4.修改配置文件/etc/named.rfc1912.zones,在文件尾部添加新区域;
zone "magine356wj.com" IN { type master; file "magine356wj.com.zone"; };
5.创建区域文件;
[[email protected] ~]# cd /var/named [[email protected] named]# vim magine356wj.com.zone
$TTL 600 @ IN SOA dns admin.magine356wj.com,. ( 2014070201 2h 10m 7d 12h) IN NS dns IN MX 10 mail dns IN A 192.168.1.199 www IN A 192.168.1.198 www IN A 192.168.1.197 www IN A 192.168.1.196 mail IN A 192.168.1.195 ftp IN CNAME www
注:@:代表的是named.rfc1912.zones中添加的magine356wj;
6.修改文件权限;
[[email protected] named]# ls -l total 32 drwxrwx---. 2 named named 4096 Jan 20 12:40 data drwxrwx---. 2 named named 4096 Jan 20 12:40 dynamic -rw-r--r--. 1 root root 252 Jun 29 08:53 magine356wj.com.zone -rw-r-----. 1 root named 1892 Feb 18 2008 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 Jan 20 12:40 slaves [[email protected] named]# chmod 640 magine356wj.com.zone [[email protected] named]# chown :named magine356wj.com.zone [[email protected] named]# ls -l total 32 drwxrwx---. 2 named named 4096 Jan 20 12:40 data drwxrwx---. 2 named named 4096 Jan 20 12:40 dynamic -rw-r-----. 1 root named 252 Jun 29 08:53 magine356wj.com.zone -rw-r-----. 1 root named 1892 Feb 18 2008 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 Jan 20 12:40 slaves
7.检查;
#named-checkconf
#named-checkzone “maine356wj.com” /var/named/magine356wj.com.zone
[[email protected] named]# named-checkconf [[email protected] named]# named-checkzone "magine356wj.com" /var/named/magine356wj.com.zone zone magine356wj.com/IN: loaded serial 2014070201 OK
8.启动服务;
9.修改默认DNS
vim /etc/resolv.conf
nameserver=192.168.1.151(修改成本地IP)
10.测试
[[email protected] named]# dig -t A www.magine356wj.com ; <<>> DiG 9.8.2rc1-RedHat-9.8.2-0.23.rc1.el6_5.1 <<>> -t A www.magine356wj.com @192.168.1.153 ;; global options: +cmd ;; Got answer: ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 41789 ;; flags: qr aa rd ra; QUERY: 1, ANSWER: 3, AUTHORITY: 1, ADDITIONAL: 1 ;; QUESTION SECTION: ;www.magine356wj.com. IN A ;; ANSWER SECTION: www.magine356wj.com. 600 IN A 192.168.1.197 www.magine356wj.com. 600 IN A 192.168.1.196 www.magine356wj.com. 600 IN A 192.168.1.198 ;; AUTHORITY SECTION: magine356wj.com. 600 IN NS dns.magine356wj.com. ;; ADDITIONAL SECTION: dns.magine356wj.com. 600 IN A 192.168.1.199 ;; Query time: 2 msec ;; SERVER: 192.168.1.153#53(192.168.1.153) ;; WHEN: Sun Jun 29 09:25:45 2014 ;; MSG SIZE rcvd: 119
时间: 2024-10-22 14:55:24