我有一个OpenVZ主机,并在其上运行多个服务(mongodb,bitcoind)。 我只打算在本地连接到他们。 他们似乎都绑定到127.0.0.2 – venet界面。 当我尝试访问127.0.0.1(客户端的默认设置)的服务时,我得不到答复。 但是连接127.0.0.2工作正常。 我没有意识到两者之间可能存在差异。 这里发生了什么事?
这是ifconfig的输出:
lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0 inet6 addr: ::1/128 Scope:Host UP LOOPBACK RUNNING MTU:16436 Metric:1 RX packets:199957 errors:0 dropped:0 overruns:0 frame:0 TX packets:199957 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:15822725 (15.8 MB) TX bytes:15822725 (15.8 MB) venet0 Link encap:UNSPEC HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00 inet addr:127.0.0.2 PtP:127.0.0.2 Bcast:0.0.0.0 Mask:255.255.255.255 inet6 addr: 2a00:1dc0:2003::adb9:ca98/128 Scope:Global inet6 addr: 2a00:1dc0:2003::a59d:5802/128 Scope:Global inet6 addr: 2a00:1dc0:2003::8d9f:638b/128 Scope:Global inet6 addr: 2a00:1dc0:2003::8638:9f63/128 Scope:Global inet6 addr: 2a00:1dc0:2003::daef:a10a/128 Scope:Global inet6 addr: 2a00:1dc0:2003::92b9:5c2a/128 Scope:Global UP BROADCAST POINTOPOINT RUNNING NOARP MTU:1500 Metric:1 RX packets:389890 errors:0 dropped:0 overruns:0 frame:0 TX packets:341645 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:367108643 (367.1 MB) TX bytes:98312087 (98.3 MB) venet0:0 Link encap:UNSPEC HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00 inet addr:178.17.169.91 PtP:178.17.169.91 Bcast:178.17.169.91 Mask:255.255.255.255 UP BROADCAST POINTOPOINT RUNNING NOARP MTU:1500 Metric:1
这是我的/ etc / hosts文件:
fe00::0 ip6-localnet ff00::0 ip6-mcastprefix ff02::1 ip6-allnodes ff02::2 ip6-allrouters 127.0.0.2 localhost.localdomain localhost # Auto-generated hostname. Please do not remove this comment. 178.17.169.91 btslots.com btslots ::1 localhost ip6-localhost ip6-loopback
我改变了localhost使它指向127.0.0.2。 我很惊讶,127.0.0.1/8子网中的两个地址可能会给出不同的结果。 除127.0.0.1之外的所有地址的行为都是相同的(和预期的一样)。
在127.0.0.0/8子网下有多个不同的环回设备并不less见。 例如,你可以在FreeBSD jail设置中实现它们来隔离到特定监狱的回环stream量。
127.0.0.0/8是任何其他子网的子网(除了发往它的stream量应该“循环”回主机内),127.0.0.1和127.0.0.2是绑定到两个不同接口的不同目的地。