为什么我的 /etc/hosts 文件没有被读取?

Wil*_*rds 0 hosts ansible

我的/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
Run Code Online (Sandbox Code Playgroud)

我已经添加了node1并且node2自然而然地将 IP0.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
Run Code Online (Sandbox Code Playgroud)

但是,我也无法按名称 ping 这些服务器:

root@ansible-server:~# ping node1
ping: unknown host node1
root@ansible-server:~# ping node2
ping: unknown host node2
Run Code Online (Sandbox Code Playgroud)

很明显我在这里做了一些非常愚蠢的事情......但是什么?

附加信息:此服务器运行 Ubuntu 14.04.2 LTS 并托管在 DigitalOcean 上。这是在 Ansible 服务器上发生的服务器。

dav*_*085 11

由于@William 仍然出错(!),我们继续:

行的格式/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 
Run Code Online (Sandbox Code Playgroud)

或者几个名字映射到同一个地址

0.0.0.0 node1 node2 node3 stitch626 
Run Code Online (Sandbox Code Playgroud)

添加,感谢 fpmurphy1 的提醒:

第一个名称(如果有多个)用作gethostbyaddretc的规范名称或“官方”名称,因此如果您有一个分配给此机器/地址的域名,通常最清晰和最有用的是放置完全合格的域名( FQDN) 作为名字。