Setup a second network interface – Linux

It has happen to me some times that when I try to use two network interfaces in a VirtualBox Virtual Machine, one for a local NAT and the another for internet access, and when verify its IP addresses just one has been assassinated. In this post I will show how to configure the interfaces to accept two NICs in a Kali Linux Virtual Machine on VirtualBox.

First of all, in the following image, we can see, I’ve added two network interfaces for the same VM, one as “NAT network” and the other one as “Host-Only Adapter”:

Adding two NICs to the VM.

For testing we can verify that once the VM is started, just one of them has an IP assigned, so when trying to make a ping request to the two different networks (local network and internet) just one responds:

What we need to do is to configure both network interfaces manually. If we consult the interfaces man pages (man interfaces), we can see an example of how to do it:

It says that we can configure eth0 to brought up at boot with:

auto eth0

And eth1 when the network card is detected as follows:

allow-hotplug eth1

Finally, we need to configure an IP method for each of them, static or dhcp, for example:

iface eth0 inet dhcp

Knowing this, we have to configure this on “/etc/network/interfaces” file. In my case, I will configure two interfaces (eth0 and eth1) as DHCP, one at boot time and the other when it is detected, so in case I need to disable one of them it won’t raise any issue:

The configuration I have to add is the following:

# eth0
auto eth0
iface eth0 inet dhcp

# eth1
allow-hotplug eth1
iface eth1 inet dhcp

Then just save the file and restart network service:

sudo /etc/init.d/networking restart

Now, we can verify IPs assigned and connectivity to both networks (local and internet in this case).

This is an easy solution to solve the problem when having two network interfaces in a Linux VirtualBox VM and just one of them is working properly. I hope this was useful.