共计 3500 个字符,预计需要花费 9 分钟才能阅读完成。
DNS 用来做主机名和 IP 地址的解析
DHCP 用来动态分配 IP
这里要做的是,使 DHCP 在分配 IP 时,动态更新 DNS 的解析记录
服务器 IP:192.168.0.202
客户端测试 IP:192.168.0.240-250
相关阅读:
Linux 系统下构建 DHCP 服务器 http://www.linuxidc.com/Linux/2013-06/86531.htm
CentOS 下配置主从 DNS 服务器以及 DHCP 下的 DDNS http://www.linuxidc.com/Linux/2013-06/85634.htm
SUSE Linux 11 pxe+DHCP+tftp+ftp 无人值守安装 http://www.linuxidc.com/Linux/2013-06/85481.htm
Linux 下架设 DHCP 服务器过程及 3 种测试 http://www.linuxidc.com/Linux/2013-05/84832.htm
Linux 上一步一步实现 DHCP 服务器 http://www.linuxidc.com/Linux/2013-04/82244.htm
1、DHCP
[root@dd ~]# yum install dhcp.x86_64 -y
[root@dd ~]# vim /etc/dhcp/dhcpd.conf
参考 /usr/share/doc/dhcp*/dhcpd.conf.sample
option domain-name “example.com”;
option domain-name-servers 192.168.0.202;
default-lease-time 600;
max-lease-time 7200;
log-facility local7;
subnet 192.168.0.0 netmask 255.255.255.0 {
range 192.168.0.240 192.168.0.250;
option routers 192.168.0.1;
}
最后需加入
ddns-update-style interim;
update-conflict-detection false;
key ddns {
algorithm hmac-md5;
secret MARnLjY0Har0LMmn8R/Biw==;
};
zone example.com. {
primary 192.168.0.202;
key ddns;
}
测试 DHCP,使用另外一台虚拟机 test,ip 为自动获取,OK
2、DNS
[root@dd mnt]# yum install bind.x86_64 bind-chroot.x86_64 -y
[root@dd mnt]# dnssec-keygen -a HMAC-MD5 -b 128 -n HOST ddns
[root@dd named]# /etc/init.d/named start
在 /var/named/chroot/etc 下 cp -p rndc.key ddns.key
更改 ddns 为
key “ddns” {
algorithm hmac-md5;
secret “MARnLjY0Har0LMmn8R/Biw==”;
};
更改 named.conf
添加 include “/etc/ddns.key”;
options {
listen-on port 53 {any;}; 监听所有
// listen-on-v6 port 53 {::1;};
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;}; 允许任何用户访问
recursion yes;
dnssec-enable yes;
dnssec-validation yes;
dnssec-lookaside auto;
/* Path to ISC DLV key */
bindkeys-file “/etc/named.iscdlv.key”;
managed-keys-directory “/var/named/dynamic”;
};
向 named.rfc1912.zones 添加
zone “example.com” IN {
type master;
file “example.com.zone”;
allow-update {key ddns;};
};
/var/named/ 复制 cp -p named.localhost example.com.zone,写入如下内容:
$TTL 1D
@ IN SOA dd.example.com. root.example.com. (
0 ; serial
1D ; refresh
1H ; retry
1W ; expire
3H ) ; minimum
NS dd.example.com.
dd A 192.168.0.202
ThinkPad A 192.168.0.1
正向解析和动态更新到此就做完了,剩下可以做做反向解析和主从 DNS
3、反向 PTR 记录
[root@dd named]# vim chroot/etc/named.rfc1912.zones
zone “0.168.192.in-addr.arpa” IN {
type master;
file “example.com.ptr”;
allow-update {none;};
};
[root@dd named]# cp -p named.loopback example.com.ptr
$TTL 1D
@ IN SOA dd.example.com. root.example.com. (
0 ; serial
1D ; refresh
1H ; retry
1W ; expire
3H ) ; minimum
NS dd.example.com.
202 PTR dd.example.com.
1 PTR ThinkPad.example.com.
[root@dd named]# dig -x 192.168.0.202
4、主从 DNS
(1)辅助 DNS 配置 IP=192.168.0.210
另外一台主机安装 DNS yum install bind bind-chroot
修改配置文件 name.conf(同上)
编辑域文件:
vim named.rfc1912.zones
zone “example.com” IN {
type slave;
masters {192.168.0.202;};(指定主 DNS 的 IP)
file “slaves/example.com.zone”;(同步的 A 纪录文件)
allow-update {none;};
};
重启 DNS 后
/var/named/chroot/var/named/slaves 目录下会生成 example.com.zone(同步而来)
(2)主 DNS 配置(master)IP=192.168.0.202
vim named.rfc1912.zones
zone “example.com” IN {
type master;
file “example.com.zone”;
allow-transfer {192.168.0.210;};(允许 210 上的 DNS 同步,【any,192.168.0.0./24】)
allow-update {none;};
};
重启 DNS
(3)测试
任一台机子指定为辅助 DNS 做解析
vim /etc/resolv.conf
nameserver 192.168.0.210(辅助 DNS)
dig dd.example.com