Linux学习之DNS+DHCP动态域名解析

DNS用来做主机名和IP地址的解析
 
DHCP用来动态分配IP
 
这里要做的是,使DHCP在分配IP时,动态更新DNS的解析记录
 
服务器IP:192.168.0.202
 
客户端测试IP:192.168.0.240-250

相关阅读:

Linux系统下构建DHCP服务

CentOS下配置主从DNS服务器以及DHCP下的DDNS

SUSE Linux 11 pxe+DHCP+tftp+ftp 无人值守安装

Linux下架设DHCP服务器过程及3种测试

Linux上一步一步实现DHCP服务器
 
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; };
 
};
 

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/8d5aaf615bac5d086f9641b2c53c0057.html