使用軟體:bind9, nsupdate

1.建立key
# dnssec-keygen -a HMAC-MD5 -b 128 -n host client
//-a 加密演算法
//-b 長度
//-n zone/host
等一陣子後畫面上會出現:
Kclient.+157+18568
並且在系統中會出現兩個檔案:
Kclient.+157+18568.key為public key,
Kclient.+157+18568.private為private key。

# cat Kclient.+157+18568.key
client. IN KEY 512 3 157 +vh-qvicyfIvnaagf3AN2g==

最後一欄為public key,要將其寫在設定檔中(這邊顯示的當然不是真的key)

2.編輯named.conf.local
加上這部份:
key "client" {
algorithm hmac-md5;
secret "+vh-qvicyfIvnaagf3AN2g==";
};


並在可以更新的zone設定裡加入:
update-policy { grant client name client.ljhuang. A; };
//grant 〈key name〉 name 〈host name〉 〈tag〉;

3.重新啟動bind9(named)
# /etc/init.d/bind9 restart

4.client端設定(Ubuntu/nsupdate)
首先要把產生的K*.key抓到client端
然後使用nsupdate這道指令
# nsupdate -k Kclient.+157+18568.key
> server 172.16.0.254 // dns server
> update delete client.ljhuang // 刪除現有紀錄
> update add client.ljhuang 600 A 172.16.0.32 // 更新紀錄
> send

若出現SERVFAIL可以檢查一下Server端的紀錄/var/log/daemon.log
如果出現以下錯誤訊息
journal file /etc/bind/db.ljhuang.jnl does not exist, creating it
/etc/bind/db.ljhuang.jnl: create: permission denied
...
journal file /etc/bind/db.ljhuang.jnl does not exist, creating it
/etc/bind/db.ljhuang.jnl: create: permission denied

先檢查 /etc/bind 的權限是不是屬於bind
另外可能就是 Ubuntu AppArmor 的問題

5.Disable one AppArmor profile
把單一profile加到disable清單中
# ln -s /etc/apparmor.d/usr.sbin.named /etc/apparmor.d/disable/
然後把正在執行中的移除掉
# apparmor_parser -R /etc/apparmor.d/usr.sbin.named
Removal succeeded for "/usr/sbin/named".

最後重新啟動bind後再試試看client端,應該就可以正常更新ip了。


參考資料:
Bind Dynamic DNS (DDNS) updates using nsupdate
系統管理員之DHCP + DNS (bind) == DDNS
Blue Labs Software :: Bind9 Dynamic DNS HowTo
Use Bind9 to setup DDNS Server
A DDNS Server Using BIND and Nsupdate
鳥哥的 Linux 私房菜 - DNS 伺服器
Study Area - Linux Servers - 架設 DNS
Study Area - DDNS tips
Debian and Ubuntu DDNS with Bind9 and DHCP
DHCP and Dynamic DNS on Ubuntu Server
Ubuntu AppArmor
arrow
arrow
    全站熱搜

    ljhuang 發表在 痞客邦 留言(1) 人氣()