When I bought a new mac mini. The first thing what I had to do is install a linux operation system into Oracle Virtual Box. But it has a big problem to set the network in Virtual Box.

I want to set two network adapter in the virtual box, the first one is NAT, the second one is "Host-only".

Add Host-only in virtual box

Let's start virtual box

First thing to do is download "Virtual Box" and "Linux Center OS" then install all of them.

When you install a linux OS into virtual box, this OS you logged we will call it "Guest", and the Mac you are using we will call it "Host".

It is easy to distinguish both of them, "Guest" could be multiple and "Host" is the only one.

When you start to install a Guest, please must select the default network "NAT", The "NAT" will let your guest use host's network, and it will be a easy beginnings for you.

Congratulation I hope you done this!

Network setting

Then, let's login your linux and see the default setting of linux in /etc/sysconfig/network-scripts/ifcfg-eth0.

  1. DEVICE=eth0
  2. HWADDR=xx:??:??:??:??:??
  3. TYPE=Ethernet
  4. UUID=ca2ae-f405c-???2-232-xxxxxxxx
  5. ONBOOT=no //change the value to be "yes"
  7. BOOTPROTO=dhcp

Because the ONBOOT value is "no", so linux won't connect to internet rightnow. We should execute command "ifup eth0" to start the network.

Next step is to check your setting of DNS server. When you start the "eth0" network, linux will auto find the DNS server and set a value into /etc/resolv.conf. Check the setting inside file content. It should look like the following content.

vim /etc/resolv.conf
  1. ; generated by /sbin/dhclient-script
  2. nameserver 192.168.?.?

Sometimes it will be setted a wrong ip. When that happen, you could change the ip by yourself. Usually the dns server is your router ip.

When you finish these setting, you could use command ping www.google.com.tw to test your network.

Result of ping
  1. ping www.google.com.tw
  2. PING www.google.com.tw ( 56(84) bytes of data.
  3. 64 bytes from tf-in-f94.1e100.net ( icmp_seq=1 ttl=63 time=35.8 ms

If you was failed to ping www.google.com, you can use the other command ping It will bypass DNS server and directly to test your network .

When you found directly ping ip is working, but ping hostname(www.google.com) is failed. You must having a wrong DNS server setting in /etc/resolv.conf.

Set a Host only network

The final step, I want to connect to "Guest machine" from my "Host Mac". But I don't know the IP of Guest machine, so we could create a "Host-only Network" in virtual box.

Open your virtual box and click "Preferences" of virtual box then select the Network and Host-Only networks. It will create a virtual network interface, we set the ip to be our network interface.

Create Host only network Host only network setting

We has new network segment now, then I want to set a ip to my Guest machine.

Open your virtual box and click "settings" of Guest then select the network. Add a new network adapter and choose the Host only network. Then save it!

New network adapter of Guest

Now restart Guest machine and login, edit file "/etc/sysconfig/network-scripts/ifcfg-eth1". Change the value of BOOTPROTO to be "static" and IPADDR to be "".

sudo vim /etc/sysconfig/network-scripts/ifcfg-eth1
  1. EVICE=eth1
  2. HWADDR=0?:x0:3?:X2:zS:?x
  3. TYPE=Ethernet
  4. #UUID=d3e8bexx-f4xx-46xx-2f81-739xxxx
  5. ONBOOT=yes
  7. BOOTPROTO=static
  8. IPADDR=

Let's restart the network of Guest. ifdown eth1 && ifup eth1.

Now I can connect to my Guest machine by using from Mac.

Network type of virtual box

NAT (Network Address Translation)

This is the most common network setting of virtual box. Do not to bother anything, just confirm you host could connect to the internet. The virtual os will use your host's network.

Host only

This type will create a new network segment like "192.168.56." . You could change the Guest IP to be and Host could connect to Guest by this IP.

Internal Networking

This type only let your Guest connect to the other Guest.

Set Host IP

I will give a static ip to my Host. The ip will be, Let my Guest machine connect to my Host.

It is not a hard setting, just edit your network of Mac and select what network which you used. In my case, I should select the Wi-Fi network. Choose the "Using DHCP with manual address" and type a ip that you want.

How to use root to start VirtualBox on Mac machine

sudo /Applications/VirtualBox.app/Contents/Resources/VirtualBoxVM.app/Contents/MacOS/VirtualBoxVM
/Applications/VirtualBox.app/Contents/Resources/VirtualBoxVM.app/Contents/MacOS/VirtualBoxVM --comment WebService --startvm 302ea398-0178-7bc4-34xazxx --no-startvm-errormsgbox

Reference material

回應 (Leave a comment)