Created
February 4, 2013 15:04
-
-
Save ianmariano/4707274 to your computer and use it in GitHub Desktop.
Autogenerate host information on ec2 on instance startup. Run from /etc/rc.local
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/bash | |
# | |
# Save somewhere and chmod o+x it and Run it from /etc/rc.local | |
# Modify and re-arrange as you see fit | |
# | |
# Change as appropriate | |
DOMAIN=local | |
USER_DATA=`/usr/bin/curl -s http://169.254.169.254/latest/meta-data/hostname` | |
HOSTNAME=`echo $USER_DATA` | |
LOCAL_IPV4=`/usr/bin/curl -s http://169.254.169.254/latest/meta-data/local-ipv4` | |
USER_DATA=`/usr/bin/curl -s http://169.254.169.254/latest/meta-data/public-hostname` | |
PUBLIC_HOSTNAME=`echo $USER_DATA` | |
IPV4=`/usr/bin/curl -s http://169.254.169.254/latest/meta-data/public-ipv4` | |
# setup | |
hostname $HOSTNAME | |
echo $HOSTNAME > /etc/hostname | |
# FQDN | |
cat<<EOF > /etc/hosts | |
# Autogenerated host information | |
127.0.0.1 localhost | |
$LOCAL_IPV4 $PUBLIC_HOSTNAME $HOSTNAME.$DOMAIN $HOSTNAME | |
# $IPV4 $PUBLIC_HOSTNAME # reference | |
# The following lines are desirable for IPv6 capable hosts | |
::1 ip6-localhost ip6-loopback | |
fe00::0 ip6-localnet | |
ff00::0 ip6-mcastprefix | |
ff02::1 ip6-allnodes | |
ff02::2 ip6-allrouters | |
ff02::3 ip6-allhosts | |
EOF |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment