Go2FullStack
Go2FullStack
How to build a Virtual Local Network in Mac

AIM

The VMs are in the same Local Area Network,they can visit each other.

Hello World!!!!!世界,你好!

The VMs’ network is separated from the Host Machine’s network.

The VMs can visit the Internet.

The VMs and the Host Machine can visit each other.

https://go2fullstack.com/wp-content/uploads/2020/11/image.png

Solution

We’ll use two Adapters in the VM: Adapter 1 (with NAT configuration) is used to visit the Internet, and the Adapter 2(with Host-only configuation) is used to build a Private Network.

https://go2fullstack.com/wp-content/uploads/2020/11/image-3.png

Step By Step

Precondition

Host Computer:MacOS Catalina (Version 10.15.5)

Please download and install the free VirtualBox Software: 

VirtualBox:  VirtualBox 6.1.16 for OSX

Download Virtual Machine ISO file from ubuntu offical site:

Virtual Machine: ubuntu-20.04.1-live-server-amd64

Step1 Create a Host Only Network in VirtualBox

Open “Host Network Manager” from the VirtualBox menu “File”->”Host Network Manager…”,and click “Create” button to create a Host Only Network. You can Enable the DHCP Server. I disabled the DHCP Server because I want to have a fixed static ip address rather than a dynamic ip address.

https://go2fullstack.com/wp-content/uploads/2020/11/image-1.png
https://go2fullstack.com/wp-content/uploads/2020/11/image-5-1024x775.png

Step2 Create a New Virtual Machine

Please follow the guild on VirtualBox manual to install a new virtual machine base on ubuntu iso file. 

Step3 Config the Host Only Network

Please “shutdown” your virtual machine first,and then click “setting”->”network”:

https://go2fullstack.com/wp-content/uploads/2020/11/image-6-1024x519.png

It has had a default NAT configuration in Adapter 1, we need to config another Adapter, so just click the “Adapter 2” tab, and select the “Enable Network Adapter” checkbox. We can use the Host-only Adapter with the “vboxnet0” that is configured in the previous steps. At last, click “OK”:

https://go2fullstack.com/wp-content/uploads/2020/11/image-4-1024x526.png

Step4 Configure the ip address of the Virtual Machine

Just start your virtual machine and login to your ubuntu operation system. Confirm your network interfaces, for example, I have a enp0s8 interface as the Host-only Adapter, next step I will configure this interface’s ip address:

https://go2fullstack.com/wp-content/uploads/2020/11/image-8.png

Create a network configuration file in the /etc/netplan/ directory, for example:.

https://go2fullstack.com/wp-content/uploads/2020/11/image-7.png

Here is the file content:

https://go2fullstack.com/wp-content/uploads/2020/11/image-2.png

And let the configurations work:

$sudo netplan apply

You can test if the VM is connect with the Host:

Ping Host Machine in your Virtual Machine:

$ping 192.168.56.1

Ping Virtual Machine in your Host Machine:

$ping 192.168.56.101

And you can add another Virtual Machine with these steps!

Leave a Reply

textsms
account_circle
email

Go2FullStack

How to build a Virtual Local Network in Mac
AIM The VMs are in the same Local Area Network,they can visit each other. Hello World!!!!!世界,你好! The VMs' network is separated from the Host Machine's network.…
Scan QR code to continue reading
2020-11-10