2014
May
05

網頁好讀版

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".

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.

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"
  6. NM_CONTROLLED=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 (173.194.72.94) 56(84) bytes of data.
  3. 64 bytes from tf-in-f94.1e100.net (173.194.72.94): 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 173.194.72.94. 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 192.168.56.1 to be our network interface.

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!

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 "192.168.56.2".

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
  6. NM_CONTROLLED=yes
  7. BOOTPROTO=static
  8. IPADDR=192.168.56.2

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

Now I can connect to my Guest machine by using 192.168.56.2 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 192.168.56.2 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 192.168.56.3, 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

網頁好讀版