私の/etc/hostsファイルが読み込まれないのはなぜですか?

私の/etc/hostsファイルが読み込まれないのはなぜですか?

私の/etc/hostsファイルは次のとおりです。

# Your system has configured 'manage_etc_hosts' as True.
# As a result, if you wish for changes to this file to persist
# then you will need to either
# a.) make changes to the master file in /etc/cloud/templates/hosts.tmpl
# b.) change or remove the value of 'manage_etc_hosts' in
#     /etc/cloud/cloud.cfg or cloud-config from user-data
127.0.1.1 ansible-server ansible-server
127.0.0.1 localhost

# 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

node1 0.0.0.0
node2 0.0.0.0

node1とを追加しましたnode2が、自然IPが0.0.0.0ノードのIPに置き換えられました。

私はこれがうまくいくと思いましたが、そうではありません。 SSHがファイルを無視すると思いますhosts

root@ansible-server:~# ssh root@node1
ssh: Could not resolve hostname node1: Name or service not known
root@ansible-server:~# ssh root@node2
ssh: Could not resolve hostname node2: Name or service not known

ただし、次のいずれかのサーバーを名前でpingすることはできません。

root@ansible-server:~# ping node1
ping: unknown host node1
root@ansible-server:~# ping node2
ping: unknown host node2

どうやら、私がここで本当に愚かなことをしているのは明らかです...しかし、何ですか?

追加情報:このサーバーはUbuntu 14.04.2 LTSを実行しており、DigitalOceanでホストされています。これはAnsibleサーバーで発生します。

ベストアンサー1

行の形式は、アドレスが/etc/hosts最初で名前が最後です。

0.0.0.0 node1 
0.0.0.0 node2 
192.168.1.1 myroutermaybe
8.8.8.8 googledns # in case DNS doesn't work for DNS???
127.0.0.1 localhost 

または、複数の名前が同じアドレスにマップされる状況

0.0.0.0 node1 node2 node3 stitch626 

通知を送ってくれたfpmurphy1に感謝します。

名前(複数の場合)は、等式または「公式」の名前として使用されますgethostbyaddr。したがって、そのコンピュータ/アドレスにドメイン名が割り当てられている場合は、通常は完全修飾ドメイン名(FQDN)を名前として使用します。

おすすめ記事