dns服务搭建
DNS 是域名系统 (Domain Name System) 的缩写,它是由解析器和域名服务器组成的。
域名服务器是指保存有该网络中所有主机的域名和对应IP地址,并具有将域名转换为IP地址功能的服务器
其中域名必须对应一个IP地址,而IP地址不一定有域名
DNS就是进行域名解析的服务器
yum install bind* -y
服务器配置文件路径 /var/named/redhat.com.zone
客户端配置文件路径 /etc/resolv.conf
需要用到named.service
正向DNS配置
vim /etc/named.conf
options {
listen-on port 53 { 10.100.52.169; };
directory "/var/named";
dump-file "/var/named/data/cache_dump.db";
statistics-file "/var/named/data/named_stats.txt";
memstatistics-file "/var/named/data/named_mem_stats.txt";
allow-query { any; };
allow-query-cache { any; };
recursion yes;
forwarders {114.114.114.114;};
};
logging {
channel default_debug {
file "data/named.run";
severity dynamic;
};
};
zone "." IN {
type hint;
file "named.ca";
};
zone "example.com" {
type master;
file "example.com.zone";
};
/var/named/redhat.com.zone
区域配置
/var/named
$TTL 1D
@ IN SOA redhat1.example.com. wan_ningxi@163.com. (
201206 ; serial
1D ; refresh
1H ; retry
1W ; expire
3H ) ; minimum
@ IN NS redhat1.example.com.
redhat1 IN A 10.100.52.169
redhat2 IN A 10.100.52.169
~
bbs IN A www CNAME
添加CNAME可以访问bbs.redhat.com
windows测试DNS
首先修改本地DNS
在网络连接中的IPV4属性里首选DNS服务器输入服务器的IP地址
安装httpd服务器
分别在服务器和客户机的/var/www/html/index.html里写入内容
分别重启服务器和客户机服务
通过浏览器登陆自己搭建的网站
linux命令行测试
vim /etc/resolv.conf 修改DNS
nameserver 172.16.40.127
命令行输入
dig www.redhat.com
可以看到 DNS IP
正向批量解析
配置文件中添加函数
$GENERATE 1-200 station$ IN A 172.16.40.$
主机名为station加了一个1到200的数字都能解析
测试 首先更改主机名
dig station50.redhat.com
主机名修改为station100.redhat.com
在浏览器中输入station100.redhat.com 也能解析到
反向解析
/etc/named.conf (查看是否添加)
options {
listen-on port 53 { 172.16.40.2; };
directory "/var/named";
dump-file "/var/named/data/cache_dump.db";
statistics-file "/var/named/data/named_stats.txt";
memstatistics-file "/var/named/data/named_mem_stats.txt";
allow-query { any; };
allow-query-cache { any; };
recursion yes;
};
zone "." {
type hint;
file "named.ca";
};
zone "example.com" {
type master;
file "example.com.zone";
};
zone "40.16.172.in-addr.arpa"{
type master;
file "40.16.172.in-addr.arpa.zone";
file "172.16.40.arpa"; (测试是否添加)
};
vim /var/named/40.16.172.in-addr.arpa.zone
添加
$TTL 1D
@ IN SOA dns.redhat.com. wangfei@openlab.cn. (
201206 ;
5m ;
15m ;
1W ;
3H ) ;
@ IN NS dns.redhat.com.
127 IN PTR www.redhat.com.
127 IN PTR www.redhat.com.
128 IN PTR server.example.com.
反向解析只能用命令行测试
在客户机/etc/resolv.conf里添加 nameserver 服务器IP
正向nslookup www.redhat.com
反向dig -x IP
dig为正向解析
反向批量解析添加$GENERATE $ 1-200 IN PTR station$.redhat.com.
反向批量解析dig -x 172.16.40.200
辅助DNS 提到容错能力 加快查询速度
需要再开一台虚拟机做辅助
yum install bind
vim /etc/named.conf
options {
listen-on port 53 { 172.16.40.129; };
directory "/var/named";
dump-file "/var/named/data/cache_dump.db";
statistics-file "/var/named/data/named_stats.txt";
memstatistics-file "/var/named/data/named_mem_stats.txt";
allow-query { any; };
allow-query-cache { any; };
recursion yes;
};
zone "." {
type hint;
file "named.ca";
};
zone "redhat.com" {
type slave;
file "slaves/redhat.com.zone";
masters{172.16.40.127;};
};
zone "40.16.172.in-addr.arpa"{
type slave;
file "slaves/40.16.172.in-addr.arpa.zone";
masters {172.16.40.127;};
};
vim /var/named/slaves/redhat.com.zone
保存退出
vim /var/named/slaves/40.16.172.in-addr.arpa.zone
保存退出
cd /var/named
修改slaves权限 766 采用递归
cd /var/named/slaver
查看该目录下是否有新增文件