Friday, July 5, 2013

Assign Static IP Address and Hostname to Guest OS in VirtualBox

One problem I've faced after changing my Network Adapter configuration to Bridged Adapter is, the IP Address changes every time I change the network, which is kind of annoying

So my requirement was to fix either IP Address or Hostname to the Guest OS, so that I can access the server running inside vm(e.g. weblogic), based on a fixed IP Address / Hostname

After trying several options and re-installations of Linux, I figured out a way

We need to use 2 Network Adapters for Guest OS
1) Bridged Adapter
    Shares the internet from Host to Guest, so that the Guest can access internet
2) Host-only Adapter
    For assigning a static IP and hostname, so that host can access guest on fixed IP / hostname

Below are the steps

During the creation of VM Image, before installing Linux, do below changes

Select Bridged Adapter for Adapter 1


 


















Go to Adapter 2 configuration, select Host-only Adapter

If you are getting error after selecting Host-only Adapter, you need to add vboxnet0 adapter first from virtualbox preferences




















During the installation of Linux, you can configure hostname and static ip address to Adapter 2

Note: We can configure hostname and static ip address, even after the installation of Linux

Enter hostname by selecting the option "manually"





















Before proceeding with the next step, note down your Adapter IP address in host machine (Mac in my case)

Open Terminal, type "ifconfig -a" to get full ip address of all the ports

Look for vboxnet0 interface, notedown the ip address (in my case: 192.168.56.1) 

Note: This step is very important, in order to access guest from host


















Now go back to Guest installation screen, select the 2nd network device
(If you want to identify which is the network device for Host-only networking, just refer the mac address from VirtualBox settings page (Select the current guest and click settings, to to Network configuration tab)

Make sure the interface ip address from Host (Mac) is in the same subnet as Guest (Linux)

In my case, I have 192.168.56.1 for my mac interface (vboxnet0) and 192.168.56.2 for my Linux network device





















Make sure hostname, static ip is properly configured in the screen and proceed to next step of installation

I didn't want to setup ipv6, so I disabled it, this is up to you























After installation, do a ping test from host to guest and guest to host, both should work fine

If you want to ping guest from host, using hostname, you need to add the hostname to /etc/hosts file in Mac

Thats all for now, seeya

1 comment:

  1. Allow the guest user to access your IP but after use you may ensure that you delete the access point so that no other person may misuse it.

    Thanks
    Silvester Norman

    Change Mac Address



    ReplyDelete