Chinaunix首页 | 论坛 | 博客
  • 博客访问: 218553
  • 博文数量: 47
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 482
  • 用 户 组: 普通用户
  • 注册时间: 2015-04-06 15:35
个人简介

贫则见廉,富则见义,生则见爱,死则见哀。

文章分类

全部博文(47)

分类: LINUX

2016-10-16 11:46:20

一、DNS正向解析[解析域名]

环境:

red hat linux 6.3

DNS-SERVER:192.168.122.1

DNS-CLIETNS:192.168.122.6


1.安转与配置DNS服务器 【server

#yum install bind  bind-chroot bind-utils -y

#vim /etc/named.conf

.. 

listen-on port 53 { any; };

listen-on-v6 port 53 { :::; };  #注意::1是只监听localhost【本地】

...     

allow-query     { any; };

//include "/etc/named.root.key";

指定读取规则:

#vim /etc/named.rfc1912.zones

...

zone "example.com" IN {

type master;

file "example.com.zone"; //这个是你的域文件的名称

allow-update { none; };

};

启动named

#/etc/init.d/named start

生成模板 (注意/var/named路径只有在named正常启动后才会有)

#cp -p /var/named/named.localhost /var/named/example.com.zone

编写规则

#vim /var/named/example.com.zone

$TTL 1D

@       IN SOA instructor.example.com. root.example.com. (

0      ; serial

1D     ; refresh

1H     ; retry

1W     ; expire

3H )    ; minimum

NS     instructor.example.com

instructor.example.com  A 192.168.122.1

server2.example.com A 192.168.122.2

server3.example.com A 192.168.122.3

server4 A 192.168.122.4

注:上面的server4是跟前面/etc/named.rfc1912.zones中写zone "example.com" IN中的example.com合成一个域名—server4.example.com                                               

2.测试: 【client

#vim /etc/resolv.conf

; generated by /sbin/dhclient-script

nameserver 192.168.122.1

search example.com

#dig server4.example.com

; <<>> DiG 9.8.2rc1-RedHat-9.8.2-0.17.rc1.el6_4.6 <<>> server4.example.com

;; global options: +cmd

;; Got answer:

;; ->>HEADER<<- opcode: QUERY, status: NXDOMAIN, id: 49794

;; flags: qr aa rd ra; QUERY: 1, ANSWER: 0, AUTHORITY: 1, ADDITIONAL: 0

;; QUESTION SECTION:

;server4.example.com. IN A

;; AUTHORITY SECTION:

example.com. 10800 IN SOA instructor.example.com. root.example.com. 0 86400 3600 604800 10800

;; Query time: 0 msec

;; SERVER: 192.168.122.1#53(192.168.122.1)

;; WHEN: Tue Aug 19 11:55:22 2014

;; MSG SIZE  rcvd: 89


二、DNS反向解析[IP进行解析]

1.配置DNS服务器 【server

#vim /etc/named.rfc1912.zones

...

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

type master;

file "westos.com.ptr";

//这里指定了要读的文件的名称 

allow-update { none; };

};

...

编写westos.com.ptr文件:

#vim /var/named/westos.com.ptr

$TTL 1D

@ IN SOA xian.example.com. root.example.com. (

0 ; serial

1D ; refresh

1H ; retry

1W ; expire

3H ) ; minimum

NS xian.example.com.

xian.example.com. A 192.168.122.2

2 PTR

9 PTR .


三、DNS双向解析

注:双向解析不是说正反向解析,而是如正向解析时,内网和外网等不同网段的IP去访问同一个域名的时候,进入了不同的域模块。

1.配置DNS服务器 【server

#vim /etc/namd.conf

//这里必须屏蔽掉,不然启动会有报错

//zone "." IN {

//      type hint;

//      file "named.ca";

//};

#这个是本地访问的时候访问的文件

view localnet{

match-clients { localhost ;};

match-destinations { localhost; };

zone "westos.com" IN {

type master;

file "westos.com.zone";

allow-update { none; };

};

};

#这个是非本地访问的文件

view internet{

match-clients { any ;};

match-destinations { any ; };

zone "westos.com" IN {

type master;

file "westos.com1.zone";

allow-update { none; };

};

#这个也必须屏蔽掉,不然启动也会有报错

//include "/etc/named.rfc1912.zones";

//include "/etc/named.root.key";


#vim /var/named/westos.com.zone

$TTL 1D

@ IN SOA xian.example.com. root.example.com. (

0 ; serial

1D ; refresh

1H ; retry

1W ; expire

3H ) ; minimum

NS xian.example.com.

xian.example.com. A 192.168.122.1

www A 192.168.122.1


#vim /var/named/westos.com1.zone

$TTL 1D

@ IN SOA xian.example.com. root.example.com. (

0 ; serial

1D ; refresh

1H ; retry

1W ; expire

3H ) ; minimum

NS xian.example.com.

xian.example.com. A 192.168.122.1

www A 192.168.122.6



本地(192.168.122.1)访问:【server】

#dig

;; QUESTION SECTION:

; IN A

;; ANSWER SECTION:

86400 IN A 192.168.122.1


客户端(192.168.122.6)访问: 【client】

#dig

;; QUESTION SECTION:

; IN A

;; ANSWER SECTION:

86400 IN A 192.168.122.6

ANY QUSTIONS

Mail: hgsadjjh@163.com

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