7,275
edits
No edit summary |
(→内部 DNS) |
||
(古い ubuntu ec2-init パッケージから流用しました)
'''ubuntu の流儀で hostname を一旦正しく設定します'''
<syntaxhighlight>▼
sudo /bin/hostname -F /etc/hostname▼
</syntaxhighlight>▼
/etc/hosts に、このインスタンスのプライベート IP address, host名, fqdn を設定します。
<syntaxhighlight>
127.0.0.1 localhost
IPADDRESS aws.example.com aws
# 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
</syntaxhighlight>
正しく host名と fqdn 設定されているかを確認します。
<syntaxhighlight>
/bin/hostname
(host名が返る)
/bin/hostname -f
(fqdnが返る)
/bin/hostname -d
(ドメイン名が返る)
</syntaxhighlight>
正常に動作したら自動化スクリプトを仕込みます。
/usr/local/etc/init に配置、実行権限を付与します。
base_url = 'http://169.254.169.254/%s/meta-data' % api_ver
my_ip = urllib.urlopen('%s/local-ipv4/' % base_url).read()
my_fqdn = os.popen("/bin
my_hostname = os.popen("/bin/hostname -s").read().rstrip()
# replace the ubuntu hostname in /etc/hosts
mp = {'localipv4' : my_ip, 'hostname' : my_hostname, 'fqdn' : my_fqdn}
t = Template(file="/usr/local/etc/bind/templates/hosts.tmpl", searchList=[mp])
/usr/local/etc/bind/templates/hosts.tmpl
127.0.0.1 localhost
# The following lines are desirable for IPv6 capable hosts
base_url = 'http://169.254.169.254/%s/meta-data' % api_ver
my_ip = urllib.urlopen('%s/local-ipv4/' % base_url).read()
my_fqdn = os.popen("/bin
ip = IP(my_ip)
my_arpa = ip.reverseName().rstrip('.')
supersede domain-name "example.com";
▲/etc/hostname に fqdn (この場合は aws.example.com) を設定します。
▲<syntaxhighlight>
▲echo "aws.example.com" | sudo tee /etc/hostname
▲sudo /bin/hostname -F /etc/hostname
▲</syntaxhighlight>
ここで一度この script を起動して動作確認します。
|