Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision | |||
bind:remote-zone-update [2013/04/10 11:38] 94.23.238.222 DWRKelHLgIFDj |
bind:remote-zone-update [2013/04/10 14:39] (current) zagi old revision restored |
||
---|---|---|---|
Line 1: | Line 1: | ||
- | Great airctle, thank you again for writing. | + | **BIND configuration** |
+ | |||
+ | Generate a key using the dnssec-keygen utility like this: | ||
+ | | ||
+ | |||
+ | and this will create two files like this: | ||
+ | |||
+ | | ||
+ | | ||
+ | |||
+ | Using the information from the public key add to your dns server configuration the key: | ||
+ | |||
+ | key user.domain.com. { | ||
+ | | ||
+ | | ||
+ | }; | ||
+ | |||
+ | where secret is the value from the public key, that in my example looks like this: | ||
+ | |||
+ | $ cat Kuser.domain.com.+157+47950.key | ||
+ | | ||
+ | |||
+ | Finally we need to allow update access | ||
+ | |||
+ | < | ||
+ | zone " | ||
+ | { | ||
+ | type master; | ||
+ | file "/ | ||
+ | | ||
+ | | ||
+ | }; | ||
+ | </ | ||
+ | |||
+ | **Using nsupdate to update the hostname** | ||
+ | |||
+ | Next we will need to upload the key we created on the EC2 image (later we will save it inside the AMI once all runs well) and test to see if it is working properly. | ||
+ | < | ||
+ | cat<< | ||
+ | server ns1.domain.com | ||
+ | zone ec2.domain.com | ||
+ | update delete test.ec2.domain.com A | ||
+ | update add test.ec2.domain.com 60 A < | ||
+ | show | ||
+ | send | ||
+ | EOF | ||
+ | </ | ||
+ | |||
+ | **Finally automation :-)** | ||
+ | |||
+ | Now we just have to put all the pieces together and using a simple script like this will do the job: | ||
+ | ec2-hostname.sh: | ||
+ | |||
+ | <code |f ec2-hostname.sh> | ||
+ | # | ||
+ | |||
+ | # you will need to have the key available in the instance in the same dir as this script | ||
+ | DNS_KEY=Kuser.domain.com.+157+47950.private | ||
+ | DOMAIN=domain.com | ||
+ | |||
+ | USER_DATA=`/ | ||
+ | HOSTNAME=`echo $USER_DATA` | ||
+ | #set also the hostname to the running instance | ||
+ | hostname $HOSTNAME.$DOMAIN | ||
+ | |||
+ | PUBIP=`/ | ||
+ | cat<< | ||
+ | server ns1.$DOMAIN | ||
+ | zone ec2.$DOMAIN | ||
+ | update delete $HOSTNAME.ec2.$DOMAIN A | ||
+ | update add $HOSTNAME.ec2.$DOMAIN 60 A $PUBIP | ||
+ | send | ||
+ | EOF | ||
+ | |||
+ | LOCIP=`/ | ||
+ | cat<< | ||
+ | server ns1.$DOMAIN | ||
+ | zone ec2-int.$DOMAIN | ||
+ | update delete $HOSTNAME.ec2-int.$DOMAIN A | ||
+ | update add $HOSTNAME.ec2-int.$DOMAIN 60 A $LOCIP | ||
+ | send | ||
+ | EOF | ||
+ | </ |