networking - How to communicate between two VirtualBox VMs running on same host

06
2014-04
  • somnathchakrabarti

    I am running two VM instances of RHEL/CentOS on my VirtualBox instance running on host Windows 7. The problem is when I am executing VBoxManage list vms -l | more and then sunsequently VBoxManage guestproperty get <uuid> "/VirtualBox/GuestInfo/Net/0/V4/IP", I can see the same IP for both the VMs. I have set the internal networking intnet for both the VMs using Networks --> Adapter 2 --> PCnet-FAST III (Internal Network, 'intnet') and my understanding was that eth0 may have been the private network interface for the VMs. But both their IP is showing as 10.0.2.15. Is there a way I can access distinct IPs in the private VM network for the two VMs?

    NOTE: I can also access only a single VM instance when accessing through Putty SSH client. And it is connecting to the proxy 127.0.0.1:2222 always. Thus I am not being able to distinguish between the VMs. I need separate instance accesses to run server and client codes on separate instances in a client-server architecture. See my other thread How to configure putty to ssh to multiple vm using same host which explains the problem in detail.

    enter image description here

    I am attaching the VBoxManage command line outputs as executed on the host. I am running 1.3_2 and 1.3_3 sandboxes but both have same IP as shown below in bold:

    C:\Program Files\Oracle\VirtualBox>VBoxManage list vms
    "Hortonworks Sandbox 1.3" {4914b5c7-1395-47f5-80ef-8fbec8cadbd4}
    "Hortonworks Sandbox 1.3_1" {f103f5d2-f949-4d67-a81e-c63ddc5335dc}
    "Hortonworks Sandbox 1.3_2" {fc2b9f50-bf4a-4a5d-8189-22d62c7e1d67}
    "Hortonworks Sandbox 1.3_3" {5976fff1-7a0d-4eca-bedf-7756f7076dbd}
    C:\Program Files\Oracle\VirtualBox>VBoxManage guestproperty get fc2b9f50-bf4a-4a
    5d-8189-22d62c7e1d67 "/VirtualBox/GuestInfo/Net/0/V4/IP"
    **Value: 10.0.2.15**
    
    C:\Program Files\Oracle\VirtualBox>VBoxManage guestproperty get 5976fff1-7a0d-4e
    ca-bedf-7756f7076dbd "/VirtualBox/GuestInfo/Net/0/V4/IP"
    **Value: 10.0.2.15**
    

    On the VM sandbox 1.3_2, I ran the below command to get the local IP for eth0 as below:

    [hue@sandbox ~]$ arp -an
    ? (10.0.2.2) at 52:54:00:12:35:02 [ether] on eth0
    [hue@sandbox ~]$ route
    Kernel IP routing table
    Destination Gateway Genmask Flags Metric Ref Use Iface
    10.0.2.0 * 255.255.255.0 U 0 0 0 eth0
    link-local * 255.255.0.0 U 1002 0 0 eth0
    default 10.0.2.2 0.0.0.0 UG 0 0 0 eth0
    

    Any ideas how can I find the distinct IPs for the different sandboxes?

    I see a similar thread how-to-do-networking-between-virtual-machines-in-virtualbox? where it is being said to use the dhcpserver for IP resolution of the guest VMs. But it asks for --ip NOTE: I tried to run the VBoxManage dhcpserver but it asks for --ip option and --netmask which I have provided as below with the following output:

    C:\Program Files\Oracle\VirtualBox>VBoxManage dhcpserver add --netname intnet --
    netmask 10.0.2.*
    Oracle VM VirtualBox Command Line Management Interface Version 4.3.0
    (C) 2005-2013 Oracle Corporation
    All rights reserved.
    
    Usage:
    
    VBoxManage dhcpserver       add|modify --netname <network_name> |
                                           --ifname <hostonly_if_name>
                                [--ip <ip_address>
                                --netmask <network_mask>
                                --lowerip <lower_ip>
                                --upperip <upper_ip>]
                                [--enable | --disable]
    
    VBoxManage dhcpserver       remove --netname <network_name> |
                                       --ifname <hostonly_if_name>
    
    
    Syntax error: You need to specify --ip option 
    

    While trying to enable the dhcpserver, it already exists:

    C:\Program Files\Oracle\VirtualBox>VBoxManage dhcpserver add --netname intnet --
    ip 10.0.2.15 --netmask 255.255.255.0 --lowerip 10.0.2.101 --upperip 10.0.2.254 -
    -enable
    VBoxManage.exe: error: DHCP server already exists
    

    The output for route -n and sudo ss -lntp are as follows: (as requested by MariusMatiae)

    [hue@sandbox ~]$ route -n
    Kernel IP routing table
    Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
    10.0.2.0        0.0.0.0         255.255.255.0   U     0      0        0 eth0
    192.168.56.0    0.0.0.0         255.255.255.0   U     0      0        0 eth1
    169.254.0.0     0.0.0.0         255.255.0.0     U     1002   0        0 eth0
    0.0.0.0         10.0.2.2        0.0.0.0         UG    0      0        0 eth0
    [hue@sandbox ~]$ sudo ss -lntp
    State      Recv-Q Send-Q        Local Address:Port          Peer Address:Port
    LISTEN     0      10                        *:8651                     *:*                                                                                              users:(("gmetad",1046,0))
    LISTEN     0      128                       *:50060                    *:*                                                                                              users:(("java",2797,86))
    LISTEN     0      10                        *:8652                     *:*                                                                                              users:(("gmetad",1046,1))
    LISTEN     0      128               10.0.2.15:50030                    *:*                                                                                              users:(("java",2834,84))
    LISTEN     0      128               127.0.0.1:34927                    *:*                                                                                              users:(("java",2797,70))
    LISTEN     0      50                        *:10000                    *:*                                                                                              users:(("java",1690,130))
    LISTEN     0      128                      :::80                      :::*                                                                                              users:(("httpd",1282,4),("httpd",1414,4),("httpd",1415,4),("httpd",1416,4),("htt                                                                                        pd",1417,4),("httpd",1418,4),("httpd",1419,4),("httpd",1420,4),("httpd",1421,4))
    LISTEN     0      128        ::ffff:10.0.2.15:60020                   :::*                                                                                              users:(("java",3513,121))
    LISTEN     0      128               10.0.2.15:8020                     *:*                                                                                              users:(("java",1886,76))
    LISTEN     0      128               10.0.2.15:50070                    *:*                                                                                              users:(("java",1886,99))
    LISTEN     0      128                      :::22                      :::*                                                                                              users:(("sshd",1191,4))
    LISTEN     0      128                       *:22                       *:*                                                                                              users:(("sshd",1191,3))
    LISTEN     0      100                      :::11000                   :::*                                                                                              users:(("java",2237,35))
    LISTEN     0      128                      :::5432                    :::*                                                                                              users:(("postmaster",1550,4))
    LISTEN     0      128                       *:5432                     *:*                                                                                              users:(("postmaster",1550,3))
    LISTEN     0      128                       *:8888                     *:*                                                                                              users:(("python",1064,5),("python",5540,5))
    LISTEN     0      1          ::ffff:127.0.0.1:11001                   :::*                                                                                              users:(("java",2237,39))
    LISTEN     0      100               127.0.0.1:25                       *:*                                                                                              users:(("master",1272,12))
    LISTEN     0      50                        *:50010                    *:*                                                                                              users:(("java",1884,75))
    LISTEN     0      128                       *:50075                    *:*                                                                                              users:(("java",1884,76))
    LISTEN     0      50                        *:9083                     *:*                                                                                              users:(("java",1797,125))
    LISTEN     0      128               10.0.2.15:50300                    *:*                                                                                              users:(("java",2834,74))
    LISTEN     0      50                        *:50111                    *:*                                                                                              users:(("java",3142,261))
    LISTEN     0      50                        *:8000                     *:*                                                                                              users:(("python2.6",3770,3),("python2.6",3843,3),("python2.6",3843,22))
    LISTEN     0      50                        *:8002                     *:*                                                                                              users:(("java",3772,136))
    LISTEN     0      50                       :::2181                    :::*                                                                                              users:(("java",2197,52))
    LISTEN     0      128               10.0.2.15:51111                    *:*                                                                                              users:(("java",2820,74))
    LISTEN     0      50                       :::48231                   :::*                                                                                              users:(("java",2197,43))
    LISTEN     0      128               127.0.0.1:199                      *:*                                                                                              users:(("snmpd",1179,8))
    LISTEN     0      50                        *:9290                     *:*                                                                                              users:(("java",2834,88))
    LISTEN     0      128                       *:8010                     *:*                                                                                              users:(("java",1884,81))
    LISTEN     0      128               10.0.2.15:50090                    *:*                                                                                              users:(("java",1888,76))
    LISTEN     0      50                        *:3306                     *:*                                                                                              users:(("mysqld",1460,10))
    
  • Answers
  • MariusMatutiae

    You have two possibilities:

    1. use bridged connections for both VMs. In this way they both have IPs on your LAN, as if they were physical machines.
    2. set up a Host-only network. This requires the following steps:

      a) File -> Preferences -> Network -> Host-only networks.

      b) Add one by clicking on the Plus sign;

      c) Hit the screwdriver -> DHCP server. Check Enable DHCP sever

      d) fill in the mask as you like. Reasonable values are: Server Address 192.168.56.254 Server mask 255.255.255.0 Lower Adrress Bound 192.168.56.100 Upper Address Bound 192.168.56.200

    Now configure your VMs to have at least one adapter on the Host-only network.

    Start you VMs, and now your host has IP 192.168.56.1, and the various VMs are located at 192.168.56.100, 192.168.56.101,... You can now ping and sssh and vnc from one machne to the others.

    EDIT:

    In view of your routing table, solution 2 will work if you give these commands on both VMs:

      sudo route delete default gw 10.0.2.2
      sudo route add default gw 192.168.56.1
    

  • Related Question

    networking - How to use CLEAR USB WiMax in Ubuntu (host) and Windows XP (guest) using VirtualBox
  • Questioner

    I'm trying to use CLEAR Motorola WiMax USB in Ubuntu as there is no support for Linux as yet. I've installed Windows XP as guest in Ubuntu and the version I'm using is 3.2.2. USB is connecting fine in Windows XP but I can't use internet in Ubuntu. Can you please tell me how to do it. Here is the configuration that could help you guys. Thanks in advance.

    I'm using Two Network Adapters.

    Network
    Adapter 1:
    PCnet-FAST III (NAT)
    Adapter 2:
    PCnet-FAST III (Host-only adapter, 'vboxnet0')
    

    ipconfig [on Guest windowsXP]

    Windows IP Configuration
    Ethernet adapter Local Area Connection:  PCnet-FAST III (NAT)
    
            Connection-specific DNS Suffix  . :
            IP Address. . . . . . . . . . . . : 10.0.2.15
            Subnet Mask . . . . . . . . . . . : 255.255.255.0
            Default Gateway . . . . . . . . . : 10.0.2.2
    
    Ethernet adapter Local Area Connection 3: PCnet-FAST III (Host-only adapter, 'vboxnet0')
    
            Connection-specific DNS Suffix  . :
            IP Address. . . . . . . . . . . . : 192.168.56.101
            Subnet Mask . . . . . . . . . . . : 255.255.255.0
            Default Gateway . . . . . . . . . :
    
    Ethernet adapter Local Area Connection 2: 
    
            Connection-specific DNS Suffix  . : CLEAR Motorola USB
            IP Address. . . . . . . . . . . . : 10.168.242.33
            Subnet Mask . . . . . . . . . . . : 255.255.192.0
            Default Gateway . . . . . . . . . : 10.168.192.2
    

    IFCONFIG [on Host Ubuntu]

    (Ethernet) eth0      Link encap:Ethernet  HWaddr 00:14:22:b9:9d:76  
              UP BROADCAST MULTICAST  MTU:1500  Metric:1
              RX packets:0 errors:0 dropped:0 overruns:0 frame:0
              TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
              collisions:0 txqueuelen:1000 
              RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)
              Interrupt:16 
    
    eth1    (Wireless) Link encap:Ethernet  HWaddr 00:13:ce:f0:9b:0d  
              inet6 addr: fe80::213:ceff:fef0:9b0d/64 Scope:Link
              UP BROADCAST MULTICAST  MTU:1500  Metric:1
              RX packets:0 errors:0 dropped:0 overruns:0 frame:0
              TX packets:1 errors:0 dropped:5 overruns:0 carrier:0
              collisions:0 txqueuelen:1000 
              RX bytes:0 (0.0 B)  TX bytes:84 (84.0 B)
              Interrupt:17 Base address:0xe000 Memory:dfcff000-dfcfffff 
    
    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:2292 errors:0 dropped:0 overruns:0 frame:0
              TX packets:2292 errors:0 dropped:0 overruns:0 carrier:0
              collisions:0 txqueuelen:0 
              RX bytes:171952 (171.9 KB)  TX bytes:171952 (171.9 KB)
    
    vboxnet0  Link encap:Ethernet  HWaddr 0a:00:27:00:00:00  
              inet addr:192.168.56.1  Bcast:192.168.56.255  Mask:255.255.255.0
              inet6 addr: fe80::800:27ff:fe00:0/64 Scope:Link
              UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
              RX packets:0 errors:0 dropped:0 overruns:0 frame:0
              TX packets:137 errors:0 dropped:0 overruns:0 carrier:0
              collisions:0 txqueuelen:1000 
              RX bytes:0 (0.0 B)  TX bytes:21174 (21.1 KB)
    

  • Related Answers
  • ta.speot.is

    You should enable ICS on the Windows XP box and set the network adapter for vboxnet0 to DHCP.

    The Windows XP guest has a DHCP server built-in for ICS. When your vboxnet0 adapter sends a DHCP request the guest should return the necessary configuration information (specifically default gateway) to allow Ubuntu to route traffic through it.

    I don't know why you have two adapters for the guest.