How do I setup a virtualbox server with a static ip?

Change the virtualbox network settings to Host-only networking and edit the following file in the virtual machine:

 /etc/network/interfaces

You can that change it to have a static IP like this:

iface eth0 inet static
       address 192.168.2.10
       netmask 255.255.255.0
       network 192.168.2.0
       broadcast 192.168.2.255
       gateway 192.168.2.1

Then, you should change the settings for the virtual Network Adaptor in Ubuntu to also have a static IP (192.168.2.1 in this example).


If like me, you happen to be on a Redhat based system like CentOS, just edit /etc/sysconfig/network-scripts/ifcfg-eth1 with the following:

DEVICE=eth1
BOOTPROTO=static
IPADDR=192.168.56.101
NETMASK=255.255.255.0

I've assigned the static IP to eth1 but you need to change it according to what ifconfig tell you. To see these changes take effect restart the network service with service network restart.