Getting the network to work in a VirtualBox VM with CentOS6

For some reason the network card for eth0 is not automagically detected by VirtualBox VM when installing a CentOS6. ( On VirtualBox running in Ubuntu 12.10 )

After some googling I found many different solutions of which none worked.
First things first: set the network interface in VirtualBox to be the PCnet-FAST III (Am79C973) networkcard. Usually I set this attached to NAT, but this does not seem to work. Attaching the adapter to one of my Ubuntu’s network interface cards by setting it to Bridged Adapter.

Restart the network service in the VM. Still no network. Only after some manual configuration in ‘/etc/sysconfig/network-scripts/ifcfg-eth0’ I got it to work. (it the ifcfg-eth0 file does not exist, create it.)

After trying out different configurations found on the net, I shuffled a bit with the possible config options and this got it to work:

DEVICE="eth0"
HWADDR=08:00:27:D0:F7:95
NM_CONTROLLED="no"
ONBOOT="yes"
BOOTPROTO="dhcp"
TYPE=Ethernet
IPV6INIT=no
PEERDNS=yes

Restart network service and go do some fun magic in your VM.

Note: don’t forget to change the HWADDR with the address of the network card from the virtualbox configuration!