Last active
December 25, 2015 13:49
-
-
Save robertstarmer/6986438 to your computer and use it in GitHub Desktop.
a user-data script that configures DNS via nsupdate
This file contains 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/bash | |
# Set the ubuntu user password to something useable for VNC/KVM console access | |
passwd ubuntu <<EOF | |
ubuntu | |
ubuntu | |
EOF | |
# Since we have non-secure Dynamic DNS updates available in the ctocllab domain | |
# this will update a ctocllab.cisco.com entry | |
hostname=`hostname` | |
dns_server=`grep nameserver /etc/resolv.conf | head -1 | awk -F' ' '{print$2}'` | |
domain=`grep search /etc/resolv.conf | awk -F' ' '{print $2}'` | |
ip_addr=`ip addr show eth0 | grep 'inet ' | tr '/' ' ' | awk -F' ' '{print $2}'` | |
nsupdate <<EOF | |
server ${dns_server} | |
update delete ${hostname}.${domain}. A | |
update add ${hostname}.${domain}. 60 A ${ip_addr} | |
show | |
send | |
answer | |
EOF | |
echo "updated DNS with ${hostname}.${domain} at ${ip_address}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment