1

I have an OpenVZ host and running several services on it (mongodb, bitcoind). I only intend to connect to them locally. They all seem to bind to 127.0.0.2 - the venet interface. When I try to access a service at 127.0.0.1 (the default for the clients), I get get no response. However connecting on 127.0.0.2 works fine. I didn't realize it was possible for there to be a difference between the two. What's happening here?

Here's an output of 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  P-t-P: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  P-t-P:178.17.169.91  Bcast:178.17.169.91  Mask:255.255.255.255
      UP BROADCAST POINTOPOINT RUNNING NOARP  MTU:1500  Metric:1

Here's my /etc/hosts file:

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

I changed localhost to have it point to 127.0.0.2. I'm surprised that it's possible for two addresses that are in the 127.0.0.1/8 subnet to give different results. All addresses besides 127.0.0.1 act the same (and as expected).

5
  • You have OpenVZ. It does networking... strangely. For a variety of reasons, I don't recommend using OpenVZ. Commented Sep 20, 2013 at 15:03
  • Can you set the listen or local address in each of those applications specifically to 127.0.0.1? Also, can you include the ipv4 content of your /etc/hosts file? You may be able to convince it to use 127.0.0.1 by mucking about with the order of lines, names and addresses in there (or you might make a total mess of things, so make a copy first) Commented Sep 20, 2013 at 18:55
  • I did notice that OpenVZ does networking "strangely". It's what is supplied by my VPS provider so switching away from it involves paying more money. I want to understand what exactly it's actually doing - OpenVZ seems to be pretty common among VPS providers so I'm assuming plenty of people manage to make it work for them.
    – Derek Hans
    Commented Sep 26, 2013 at 12:04
  • I can indeed switch the IP address used by the clients and am doing that currently. Though I would still like to understand what is happening.
    – Derek Hans
    Commented Sep 26, 2013 at 12:06
  • OpenVZ is pretty common, but that doesn't make it good, or appropriate for a given purpose. Commented Sep 26, 2013 at 15:55

1 Answer 1

2

Having multiple, different loopback devices under 127.0.0.0/8 subnet is not uncommon. For example, you can implement them in FreeBSD jail setups to isolate loopback traffic to the specific jails.

127.0.0.0/8 is a subnet like any other subnet (with the exception that traffic destined to it should "loop" back inside the host), and 127.0.0.1 and 127.0.0.2 are distinct destinations when they are bound to two different interfaces.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .