bind9在view情況下通過TSIG key實現nsupdate功能


1、使用dnssec-keygen -a HMAC-MD5 -b 128 -n USER testkey命令來生成密鑰。
    dnssec-keygen:用來生成更新密鑰。
    -a HMAC-MD5:采用HMAC-MD5加密算法。
    -b 128:生成的密鑰長度為128位。
    -n USER testkey:密鑰的用戶名為testkey。
2、密鑰生成后,會在當前目錄下自動生成兩個密鑰文件***.+157+xxx.key和***.+157+xxx.private。
3、查看兩個密鑰文件的內容:
    cat ***.+157+xxx.key
    cat ***.+157+xxx.private
4、通過同樣的方法生成test2key。
5、添加密鑰信息到DNS主配置文件中 
vi /etc/named.conf
key testkey {
algorithm hmac-md5;                // algorithm:指明生成密鑰的算法。
secret J+mC6Q29xiOtNEBySR4O1g==;   // secret:指明密鑰串。
};
key test2key {
algorithm hmac-md5; 
secret PpRyh6fU1ejnutT+jafXag==; 
};
 
 6 、將test.com區域中的allow-update { none; }中的“none”改成“key testkey”;
      將“none”改成“key testkey”的意思是指明采用“key testkey”作為密鑰的用戶可以動態更新“test.com”區域。
示例如下:
key  " testkey " {
    algorithm hmac-md5;
    secret  " 3UHeiKTGzDv+hBpS0A9trg== ";
};   
key  " test2key " {
    algorithm hmac-md5;
    secret  " PpRyh6fU1ejnutT+jafXag== ";
};  
 
view "external-test" in {
  match-clients { key testkey; acl1; };  //key testkey; 以及acl1;
 zone  " test.com " { 
    type master; 
    file  " test.zone "
    allow-update { key testkey; };
    //allow-transfer { key testkey; };
};
};
view "external-test2" in {
  match-clients { key test2key; acl2; };
 zone  " test.com " { 
    type master; 
    file  " test2.zone "
    allow-update { key test2key; };
    //allow-transfer { key testkey; };
};
};
 7、總結

  以上示例可以實現通過正確的key和acl對兩個view進行nsupdate。但bind的acl匹配原則是:"由上而下,匹配即退出",並且match-clients{}中的參數是"or"的關系。當執行nsupdate命令時,執行端(一般都是主dns或管理機)所用的ip地址不應該包含在acl1或者acl2中(最后一個view的match-clients{aclx}可包含也可不包含),否則按照以上原則,執行端主機只能訪問包含其ip的view了,其它view的訪問都將被拒絕。

  按照以上配置運行bind,在bind主機上執行nsupdate,
  命令是: nsupdate -y test2key:PpRyh6fU1ejnutT+jafXag==
             >zone test.com
             >update add www123.test.com 86400 A 192.168.99.100
             >send
  返回錯誤結果: update failed: REFUSED
  錯誤分析:執行nsupdate的主機地址包含在acl1中, 進入了view "external-test"執行更新,顯然key不匹配,被拒絕。
  解決辦法:在view "external-test"的 match-clients{}中將執行nsupdate主機的地址(bind主機地址)排除掉,
                  命令:match-clients{ key testkey; !127.0.0.1; !x.x.x.x; acl1;} //x.x.x.x填寫bind主機真實ip地址
  
 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM