Last Updated: February 25, 2016
· enno
Bugginout 150

Static IP Address for Virtualbox Linux VM

If you want to ssh into your VM from the host OS, you need to add a host-only network to your VM in addition to the NAT adapter that is configured by default.

Virtualbox assigns each of those host-only adapters an IP address from its DHCP range in the order the VMs were started and sent a DHCP request. It does not pin IPs to MAC addresses or anything, so the only way to have a static, reliable IP address is not to make the OS use DHCP in the first place.

In Linux, this is done in /etc/network/interfaces. If eth1 is your host-only network (second adapter in the VM settings), then add the following:

iface eth1 inet static

Mistake I made when copying this from a recipe somewhere else: Do not add a gateway, or you'll lose access to the internet at large.

Now add that IP and the hostname you've given the machien to your hosts file, and never worry about it again. You probably aren't going to run more than a handful of VMs on your host, so it isn't too hard to make sure you are not accidentally using the same IP address twice.

Say Thanks
Filed Under