Last active
April 12, 2022 08:03
-
-
Save Himura2la/b1a631871b82a551ed132ab44fd35d4e to your computer and use it in GitHub Desktop.
Update a DNS record automatically after getting an IP address from DHCP
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# /etc/dhcp/dhclient-exit-hooks.d/nsupdate | |
[ "$interface" != "eth0" ] && return | |
[ "$new_domain_name" != "example.org" ] && return | |
if [ "$reason" = BOUND ] || [ "$reason" = RENEW ] || | |
[ "$reason" = REBIND ] || [ "$reason" = REBOOT ] | |
then | |
host="$(hostname)" | |
nsupdatecmds=/var/tmp/nsupdatecmds | |
echo "update delete $host.$new_domain_name a" > $nsupdatecmds | |
echo "update add $host.$new_domain_name 3600 a $new_ip_address" >> $nsupdatecmds | |
echo "send" >> $nsupdatecmds | |
nsupdate $nsupdatecmds | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment