基于bind和dhcp搭建DDNS服务

DNS是用来解析域名得到IP地址的协议,它要求服务器的IP地址是静态不变的。然而为了获得静态IP地址,通常需要向ISP支付额外的费用。DDNS(Dynamic domain server),是将服务器的动态IP地址映射到一个固定的域名(FQDN)解析服务上,用户每次访问服务的时候使用服务器的域名进行访问,DDNS会将服务器的动态IP地址返回给用户,这样服务就绑定在域名上而非绑定在一个静态的IP之上。

1. bind配置

/etc/named.conf

key "rndc-key" {
    algorithm hmac-md5;
    secret "+UlPBwU6Mz8QNaJLnmZV+68mTa0oAHqUk4Zh9Fj77LfWpHeWzGQS0kcDONjz14w+sq894B/MyhC3Oexo7j+Y3w==";
};

options {

    # The directory statement defines the name server's working directory
    directory "/var/lib/named";

    # Write dump and statistics file to the log subdirectory.  The
    # pathenames are relative to the chroot jail.
    dump-file "/var/log/named_dump.db";
    statistics-file "/var/log/named.stats";

};

controls {
    inet 127.0.0.1 allow { any ;} keys { "rndc-key" ; } ;
};

zone "example.com" {
    type master;
    file "example.com.zone";
    allow-update { key "rndc-key";};
    notify yes;
};

# The following zone definitions don't need any modification.  The first one
# is the definition of the root name servers.  The second one defines
# localhost while the third defines the reverse lookup for localhost.

zone "." in {
    type hint;
    file "root.hint";
};

zone "localhost" in {
    type master;
    file "localhost.zone";
};

zone "0.0.127.in-addr.arpa" in {
    type master;
    file "127.0.0.zone";
};

example.com.zone

$ORIGIN .
$TTL 604800 ; 1 week
example.com     IN SOA  example.com. root.example.com. (
                20001120   ; serial
                172800     ; refresh (2 days)
                14400      ; retry (4 hours)
                3628800    ; expire (6 weeks)
                604800     ; minimum (1 week)
                )
            NS  example.com.
            A   127.0.0.1
$ORIGIN example.com.

2. dhcp配置

key "rndc-key" {
    algorithm hmac-md5;
    secret "+UlPBwU6Mz8QNaJLnmZV+68mTa0oAHqUk4Zh9Fj77LfWpHeWzGQS0kcDONjz14w+sq894B/MyhC3Oexo7j+Y3w==";
};

ddns-update-style   interim;
ddns-updates        off;

default-lease-time 1800;
subnet 10.112.127.0 netmask 255.255.255.128 {
  range 10.112.127.1 10.112.127.126;
  option routers 10.112.127.120;
  option broadcast-address 10.112.127.127;
  default-lease-time 900;
  max-lease-time 17280;
  option domain-name "example.com";
  option domain-name-servers 10.112.127.2;

  authoritative;
  ddns-domainname   "example.com."; 
  ddns-updates      on;
  allow         client-updates;
  allow         unknown-clients;
  
  zone example.com. {
    primary 10.112.127.2;
    key rndc-key;
  }
}
subnet ...{
}

参考资料:

posted @ 2011-03-29 11:28  千里快哉  阅读(1149)  评论(0)    收藏  举报