Page 1 of 1

Can not ping NIC from another NIC on same VM

Posted: 26. Feb 2013, 01:00
by trt44
I have Ubuntu guest installed with two virtual network adapters : Internal network adapter + Bridged Adapter.
The bridged adapter is using DHCP for connectivity configuration and works well. The internal network adapter is configured manually so i can simulate a cross cable connection with another Ubuntu guest and also works well. The internal network adapter has this configuration :

Code: Select all

    IP : 192.168.1.100
    MASC : 255.255.255.0
    GW : --
    DNS : --
My router is providing to the bridged adapter an IP in the range 192.168.1.0/24 (actually it has 192.168.1.37).
Now i want to be able to ping from the bridged adapter to the internal network adapter and viceversa because right now i can not do it. Basically i want to establish my Bridged adapter IP as the internal networks adapter gateway so any traffic coming from my internal network (two ubuntu guests) through the internal network adapter can reach internet.
Here is my complete scenario :

Code: Select all

    Windows Host <------- Bridged Connection --------> Ubuntu Guest 1 <-------- Internal network ------> Ubuntu Guest 2
My "Ubuntu guest 1" can access internet through the bridged adapter correctly. Between "Ubuntu Guest 1" and "Ubuntu Guest 2" i can ping in both directions and captures traffic in Wireshark through the internal network adapters that both VMs have. I am only missing the interconnection between the adapters in my "Ubuntu guest 1" as explained.

Re: Can not ping NIC from another NIC on same VM

Posted: 26. Feb 2013, 03:17
by Perryg
You should read 6 Virtual networking in your VirtualBox users manual to see why this does not work.
Basically if you simply want to add the Internet to the guests add a second adapter set to NAT.

If you have the first guest setup with two adapters (one bridged and one internal) you could use iptable to provide the routes and configure the second guest accordingly.

Note: putting the internal in the same subnet is not advised as it can cause issues.

Re: Can not ping NIC from another NIC on same VM

Posted: 3. Mar 2013, 03:26
by trt44
Can you give me more details please, i failed to make it work.

Re: Can not ping NIC from another NIC on same VM

Posted: 3. Mar 2013, 03:37
by Perryg
1) the adapters that are using Internal need to be using a different subnet than the host or the Bridged adapter of the first guest.
2) add a second adapter to the guest that just has the internal adapter set to NAT to be able to connect to the Internet, or add a route from the first guest to the second guest using iptables. https://help.ubuntu.com/community/IptablesHowTo

Re: Can not ping NIC from another NIC on same VM

Posted: 5. Mar 2013, 00:04
by trt44
Thank you, i have solved the problem and here i post the solution maybe someone will be interested.
Step 1 : Enable forwarding (firewall and NAT)

Code: Select all

echo 1 > /proc/sys/net/ipv4/ip_forward
Step 2 : Enable NAT on the adapter connected to internet

Code: Select all

iptables -t nat --append POSTROUTING --out-interface eth2 -j MASQUERADE
Step 3 : Specify the adapter that we want to let its traffic to go out to intrernet

Code: Select all

iptables --append FORWARD --in-interface eth1 -j ACCEPT