Networking – Setting up static IP for virtualbox

arpnetworkingvirtualbox

I was learning arpspoofing.I was using my Ubuntu machine as the Man in the middle, an Ubuntu in my virtualbox as the target and my default gateway(Which is 10.7.1.2) as the target gateway. In order to sniff the traffic between two machines the machines must be in the same network. When I checked route -n on my virtualbox host it showed that it uses the gateway address 10.0.2.2 which is different from the one I use for my host machine.

Is it possible to bring the virtualbox to my network and assign any static IP like 10.7.1.x?

Best Answer

In the VB guest configuration for the Ubuntu, change the network adapter 1 type from NAT to Bridged Adapter.

Then start Ubuntu guest and change as root (or sudo) the /etc/network/interfaces to setup a static interface:

auto eth0
iface eth0 inet static
    address 10.7.1.7
    netmask 255.255.255.0
    gateway 10.7.1.2

And make sure to remove or comment out any stanza mentioning dhcp. Restart your network with sudo service networking restart or restart your guest.

If you need domain name resolution on the Ubuntu guest, you will also have to add a DNS in the /etc/resolv.conf. For example

nameserver 8.8.8.8