dhcp获取ip后自动更新DNS 博客分类: linux
程序员文章站
2024-03-17 22:17:46
...
添加/etc/dhcp/dhclient-exit-hooks文件,使之可执行
内容如下
内容如下
#!/bin/bash echo "" echo "dhclient-exit-hooks running..." echo "reason is ${reason}" echo "interface is ${interface}" # only execute on the primary nic if [ "$interface" != "eth0" ] then exit 0; fi # when we have a new IP, perform nsupdate if [ "$reason" = "BOUND" ] || [ "$reason" = "RENEW" ] || [ "$reason" = "REBIND" ] || [ "$reason" = "REBOOT" ] then echo "new_ip_address: ${new_ip_address}" host=$(hostname | cut -d'.' -f1) domain=$(hostname | cut -d'.' -f2- -s) IFS='.' read -ra ipparts <<< "$new_ip_address" ptrrec="${ipparts[3]}.${ipparts[2]}.${ipparts[1]}.${ipparts[0]}.in-addr.arpa" nsupdatecmds="/tmp/nsupdate" resolvconfupdate="/tmp/resolvconfupdate" echo "updating resolv.conf" grep -iv "search" /etc/resolv.conf > "$resolvconfupdate" echo "search $domain" >> "$resolvconfupdate" cat "$resolvconfupdate" > /etc/resolv.conf echo "Attempting to register $host.$domain and $ptrrec" { echo "update delete $host.$domain a" echo "update add $host.$domain 600 a $new_ip_address" echo "send" echo "update delete $ptrrec ptr" echo "update add $ptrrec 600 ptr $host.$domain" echo "send" } > "$nsupdatecmds" nsupdate "$nsupdatecmds" fi exit 0;
上一篇: python 各类排序方法
下一篇: 最长公共子序列