我的/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
并且自然地,该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
但是,我也不能通过它们的名称来对这些服务器执行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服务器上发生的服务器。
由于@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
或多个名称映射到同一地址
0.0.0.0 node1 node2 node3 stitch626
已添加,感谢fpmurphy1的提醒:
名字(如果有多个)被用作等的规范名称或“正式”名称gethostbyaddr
,因此,如果您为该机器/地址分配了域名,通常最清楚,最有用的是放置完全合格的域名( FQDN)作为名字。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句