Bind + dhcpd for dynamic ddns

Source: Internet
Author: User

Objectives:

After obtaining the dhcp ip address, the customer automatically registers the currently used host name with the BIND server to enable automatic domain name resolution.

 

Principle:

Bind is used for domain name resolution. To prevent all users from updating the dns server, use the key for data update Verification

When an IP address is allocated, dhcpd sends the DNS update key to the customer at the same time. The customer automatically registers with the BIND server.

 

Install dns server software

[root@station149 /]# yum install -y bind*Installed:  bind.x86_64 32:9.8.2-0.17.rc1.el6_4.6                         bind-chroot.x86_64 32:9.8.2-0.17.rc1.el6_4.6  bind-devel.x86_64 32:9.8.2-0.17.rc1.el6_4.6                   bind-dyndb-ldap.x86_64 0:2.3-5.el6  bind-sdb.x86_64 32:9.8.2-0.17.rc1.el6_4.6Complete!


Create a key

[root@station149 /]# rndc-confgen -r /dev/urandom -awrote key file "/etc/rndc.key"[root@station149 /]# chown named:named /etc/rndc.key[root@station149 /]# chown 644 /etc/rndc.key

 

Current key file content

key "rndckey" {        algorithm hmac-md5;        secret "qUGWW02EZVKUNMK/iorkgg==";};

Copy the key content to bind, dhcp configuration, or optional File Import method using include to load the key


Bind configuration file Definition

Vi/var/named/chroot/etc/named. conf

Options {directory "/var/named"; forwarders {8.8.8.8 ;};}; key "rndckey" {algorithm hmac-md5; secret "qUGWW02EZVKUNMK/iorkgg = ";}; # The following definition only supports DNS update through local DHCP controls {inet 127.0.0.1 allow {127.0.0.1 ;}keys {rndckey ;}; zone "cloud.com. "IN {type master; file" cloud.com. master. zone "; allow-update {key rndckey ;};}; zone" 48.168.192.in-addr. arpa. "IN {type master; file" 48.168.192.in-addr. arpa. master. zone "; allow-update {key rndckey ;};};



Forward zone configuration file
Vi/var/named/chroot/var/named/cloud.com. master. zone

$TTL 86400@ IN SOA station149.cloud.com. root.station149.cloud.com. (        2014011510        1400        2300        25000        86400 )@       IN              NS      station149.cloud.com.station149              IN      A       192.168.48.149

 

Reverse zone configuration file

vi /var/named/chroot/var/named/48.168.192.in-addr.arpa.master.zone$TTL 86400@ IN SOA station149.cloud.com. root.station149.cloud.com. (        2014010810        1400        2300        25000        86400 )@       IN              NS      station149.cloud.com.149             IN      PTR     station149.cloud.com.

 

Note: currently, only forward and reverse configuration files are configured. Other hosts use the DDNS Method for Automatic Registration.

 

Start bind and verify

[Root @ station149/] # chown named: named/var/named/chroot/var/named /*. zone [root @ station149/] # service named restart stop named: [OK] Start named: [OK]


Dns Client Configuration

[root@station149 ~]# vi /etc/resolv.confsearch clound.comnameserver 192.168.48.149


Test

[root@station149 ~]# host station149.cloud.comstation149.cloud.com has address 192.168.48.149[root@station149 ~]# host 192.168.48.149149.48.168.192.in-addr.arpa domain name pointer station149.cloud.com.[root@station149 ~]# host www.google.com.hkwww.google.com.hk is an alias for www-wide.l.google.com.www-wide.l.google.com has address 74.125.128.199www-wide.l.google.com has IPv6 address 2404:6800:4005:c00::c7


DHCP server configuration

Software Installation

[root@station149 ~]# yum install -y dhcpInstalled:  dhcp.x86_64 12:4.1.1-38.P1.el6.centosComplete!


Vi/etc/dhcp/dhcpd. conf

key "rndckey" {        algorithm hmac-md5;        secret "qUGWW02EZVKUNMK/iorkgg==";};ddns-domainname "cloud.com.";ddns-update-style interim;ddns-rev-domainname "in-addr.arpa.";ddns-updates on;authoritative;#master server for this domain# Allow only the DHCP server to update DNSignore client-updates;allow unknown-clients;host pdc {   hardware ethernet 00:0B:2B:17:2F:00;   fixed-address 192.168.48.2;}zone  48.168.192.in-addr.arpa {        primary 127.0.0.1;        key rndckey;}zone cloud.com {        primary 127.0.0.1;        key rndckey;}subnet 192.168.48.0 netmask 255.255.255.0 {        range                        192.168.48.20 192.168.48.126;        default-lease-time              86400;        max-lease-time                172800;        option subnet-mask             255.255.255.0;        option broadcast-address        192.168.48.255;        option routers                 192.168.48.1;        option domain-name            "cloud.com.";        option domain-name-servers     192.168.48.149;}


Start dhcpd

service dhcpd start


 

Notes:

Observe dhcp server

[Root @ station149 etc] # cat/var/lib/dhcpd. leases

# The format of this file is documented in the dhcpd.leases(5) manual page.# This lease file was written by isc-dhcp-4.1.1-P1server-duid "\000\001\000\001\032i\023^\000PV\201\350\247";lease 192.168.48.60 {  starts 3 2014/01/15 09:38:11;  ends 4 2014/01/16 09:38:11;  cltt 3 2014/01/15 09:38:11;  binding state active;  next binding state free;  hardware ethernet 00:50:56:81:72:9d;  client-hostname "terry";}


If the client-hostname "terry"; information cannot be found
You need to configure the client and add the DHCP_HOSTNAME configuration.

 

Refer to client configuration information

[root@terry sysconfig]# cat /etc/sysconfig/networkNETWORKING=yesHOSTNAME=terryDHCP_HOSTNAME=terry

 

Refer to updates to bind server logs

Jan 15 17:40:42 station149 named-sdb[5646]: client 127.0.0.1#46556: signer "rndckey" approvedJan 15 17:40:42 station149 named-sdb[5646]: client 127.0.0.1#46556: updating zone 'cloud.com/IN': adding an RR at 'terry.cloud.com' AJan 15 17:40:42 station149 named-sdb[5646]: client 127.0.0.1#46556: updating zone 'cloud.com/IN': adding an RR at 'terry.cloud.com' TXTJan 15 17:40:42 station149 named-sdb[5646]: cloud.com.master.zone.jnl: create: permission deniedJan 15 17:40:42 station149 named-sdb[5646]: client 127.0.0.1#46556: updating zone 'cloud.com/IN': error: journal open failed: unexpected errorJan 15 17:40:42 station149 dhcpd: Unable to add forward map from terry.cloud.com. to 192.168.48.60: timed outJan 15 17:40:42 station149 dhcpd: DHCPREQUEST for 192.168.48.60 from 00:50:56:81:72:9d (terry) via eth0Jan 15 17:40:42 station149 dhcpd: DHCPACK on 192.168.48.60 to 00:50:56:81:72:9d (terry) via eth0

 

Note whether the/var/name/chroot/var/named directory can be read and written by the user's named.

 

Assuming everything is normal, the jnl suffix file is automatically generated in the/var/named/chroot/var/named directory.

[root@station149 named]# cd /var/named/chroot/var/named/[root@station149 named]# ls *.jnl48.168.192.in-addr.arpa.master.zone.jnl  cloud.com.master.zone.jnl

 

Finally, the computer automatically registers terry.cloud.com and the corresponding IP address in the DNS for verification:

[root@station149 named]# host terry.cloud.comterry.cloud.com has address 192.168.48.60[root@station149 named]# host 192.168.48.6060.48.168.192.in-addr.arpa domain name pointer terry.cloud.com.



 

 



 



 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.