Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Connect two virtualbox machine

I have a virtual machine attached to NAT. It has the default IP 10.0.2.15. Now I create another machine but the new machine still has the same IP address 10.0.2.15. Is there a way that I can keep the network setting for the first machine, change the second machine's IP to something like 10.0.3.15 and make those two machine able to ping to each other (as in a LAN network) ?

like image 938
dondon Avatar asked Feb 05 '26 19:02

dondon


1 Answers

Solution

Use NAT Network instead of NAT.

This worked for me with VirtualBox version 5.2.22 and Redhat/Ubuntu. The VM's had different IP's and both had access to internet.

For, both VM's :

  1. turn them off
  2. right-click the VM -> setting -> network : select Nat Network in attached to select Allow VMs in Promiscuous mode (advanced chevron)
  3. turn them on
  4. use ifconfig (or ip addr) command to find out each VM IP. In my case : 10.0.2.4 and 10.0.2.5

The following table provides an overview of the most important networking modes:

|          | VM <-> Host | VM1 <-> VM2 | VM -> Internet | VM <- Internet |
|----------|-------------|-------------|----------------|----------------|
| HostOnly | Yes         | Yes         | No             | No             |
| Internal | No          | Yes         | No             | No             |
| Bridged  | Yes         | Yes         | Yes            | Yes            |
| NAT      | No          | No          | Yes            | Port forward   |
| NATNet   | No          | Yes         | Yes            | Port forward   |

NB: If you want to connect to the VMs with tty, you need to do ip forwarding.

In the Virtualbox config:

  • File -> Preference -> Network -> double-clic Natnetwork -> port fordwarding -> add a rule : host ip 127.0.0.1, port 23 (or whatever to put in tty), Guest IP (the VM ip, example: 10.0.2.5), guest port 22

More explanation here

like image 184
Slim Aloui Avatar answered Feb 12 '26 15:02

Slim Aloui