Skip to content

Instantly share code, notes, and snippets.

@Himura2la
Last active April 12, 2022 08:03
Show Gist options
  • Save Himura2la/b1a631871b82a551ed132ab44fd35d4e to your computer and use it in GitHub Desktop.
Save Himura2la/b1a631871b82a551ed132ab44fd35d4e to your computer and use it in GitHub Desktop.
Update a DNS record automatically after getting an IP address from DHCP
#!/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