官术网_书友最值得收藏!

  • Linux Networking Cookbook
  • Gregory Boyce
  • 616字
  • 2021-07-02 16:32:46

Configuring dynamic DNS on your local network

Right now you get your IP address configured automatically via DHCP and you're able to resolve DNS records from the internet via your DNS server. With the use of Dynamic DNS, you can also leverage your DNS server to address your local systems by name as well.

How to do it…

Let's configure dynamic DNS on your local network:

  1. First, we need to configure your bind instance to host DNS for your internal domain, as well as reverse DNS for your IP range. For our example, we'll use a domain of example.org:
    zone "example.org" {         
      type master;
      notify no; 
      file "/var/lib/bind/example.org.db";
    }
    zone "0.168.192.in-addr.arpa" {      
      type master;
      notify no; 
      file "/var/lib/bind/rev.1.168.192.in-addr.arpa"; 
    };
  2. Next we populate the zone in example.org.db:
    example.org.  IN  SOA  router.example.org. admin.example.org. (
      2015081401
      28800
      3600
      604800 
      38400
    )  
    example.org.     IN      NS      ns1.example.org.
    router    IN      A       192.168.1.1
  3. Then we populate the reverse zone in rev.1.168.192.in-addr.arpa:
    @ IN SOA ns1.example.org. admin.example.org. (
      2006081401
      28800
      604800
      604800
      86400  
    )  
    IN    NS     ns1.example.org. 
    1                    IN    PTR    router.example.org.
  4. In order to connect the DHCP and DNS services, we need to generate a HMAC key for securing the communication. This can be completed by executing dnssec-keygen -a HMAC-SHA512 -b 512 -r /dev/urandom -n USER DDNS. This command will generate a pair of files named Kddns_update.+NNN+NNNNN.private and Kddns_update.+NNN+NNNNN.key.
  5. Create a file called ddns.key and insert the following content with <key> replaced by the string marked Key: in the .private file:
    key DDNS {
      algorithm HMAC-SHA512;
      secret "<key>"; 
    };
  6. Copy ddns.key to both /etc/dhcp and /etc/bind with the proper permissions using the following:
    # install -o root -g bind -m 0640 ddns.key \
    /etc/bind/ddns.key
    # install -o root -g root -m 0640 ddns.key \
    /etc/dhcp/ddns.key
  7. Tell bind about the DDNS updating key by adding it to /etc/bind/named.conf.local:
    include "/etc/bind/ddns.key";
  8. Then tell bind to allow updating of the zones you previously created by adding an allow-update entry to your zones so that they look similar to the following:
    zone "example.org" {         
      type master;
      notify no;
      file "/var/lib/bind/example.org.db";
      allow-update { key DDNS; };
    }
  9. Now we need to update the DHCP server to have it hand out your nameserver instead of Google's and send hostname updates to your DNS server using the correct key:
    option domain-name "example.org";
    option domain-name-servers 192.168.1.1;
    default-lease-time 600;
    max-lease-time 7200;
    authoritative;
    ddns-updates           on;
    ddns-update-style      interim; 
    ignore                 client-updates; 
    update-static-leases   on;
    include "/etc/dhcp/ddns.key"; 
    
    subnet 10.0.0.0 netmask 255.255.255.0 {
      range 10.0.0.10 10.0.0.100;
      option routers 10.0.0.1;
    }
    zone EXAMPLE.ORG. {   
      primary 127.0.0.1;   
      key DDNS; 
    }  
    
    zone 2.168.192.in-addr.arpa. {   
      primary 127.0.0.1;   
      key DDNS; 
    } 

How it works…

Bind/named supports the ability to dynamically update DNS records through the use of clients, which are configured to sign the update messages using HMAC. The server is able to validate the authenticity of the messages by performing the same hashing operation that the client had performed with the same shared key. If the hash value sent by the client with the message matches the hash value calculated locally by the server, then we know that the client and server both have the same shared key.

This dynamic update feature can be leveraged to create/modify DNS records on the fly using the nsupdate command. In our case, we're going to have ISC DHCPD send the update commands directly, as new hosts are found.

As a system requests an IP address through the DHCP protocol, the client includes its hostname as a part of the initial discovery request. This hostname is recorded as a part of the lease. When ISC DHCP is set up for DDNS, it issues a DNS update request to the configured DNS server. Now your system is resolvable by other clients, at least until its lease expires.

主站蜘蛛池模板: 大宁县| 黎城县| 洪泽县| 岳池县| 南和县| 潍坊市| 叶城县| 延吉市| 新丰县| 西吉县| 出国| 栾城县| 长宁区| 梁山县| 巫山县| 玉树县| 尚义县| 无极县| 郧西县| 苍溪县| 汉中市| 乌兰浩特市| 汤原县| 抚远县| 临猗县| 武强县| 石屏县| 迁安市| 宜兰县| 宜兴市| 克什克腾旗| 荣成市| 彰化县| 潞西市| 榆中县| 建德市| 邹城市| 麟游县| 仁寿县| 平谷区| 会同县|