Search This Blog

Saturday, February 14, 2015

GNS3 - VirtualBox Part 9: Adding More Than Four NICs to VirtualBox VMs


The VirtualBox GUI manages up to four NICs.  You may add up to eight NICs using the VBoxManage command line interface (CLI).  This article demonstrates how to add and configure eight NICs for a VirtualBox/GNS3 guest.

Introduction

As illustrated above, the VirtualBox GUI only supports four NICs (Adapters 1-4) through the GUI.  this is adequate for servers, but Linux also supports Layer 2 switching and Layer 3 routing; it is a viable option for networking devices in virtualized environments such as Xen and VMWare.  VirtualBox is not an enterprise option, but it is a useful sandbox.  However, four interfaces is not adequate for configuring bonded interfaces and larger switches.


Although the GUI only supports four interfaces, VirtualBox supports up to eight.  If you open the .vbox configuration files in a VM guest's directory, there are a series of sections for Adapter Slots 0-3 beginning with:

<Adapter slot="0" enabled="true" MACAddress="080027FB40D9" cable="true" speed="0" type="82540EM">
There are also a series of sections for Adapter Slots 4-7 beginning with:
<Adapter slot="4" enabled="false" MACAddress="0800272DB7A5" cable="false" speed="0" type="82540EM">
The additional adapters are there, but disabled and not "cabled," or connected to a virtual network.

VBoxManage / GNS3 NIC Configuration

The VBoxManage CLI utility configures adapters 5-8 (in Slots 4-7) and may also be used to modify any existing NICs.  This utility is invoked as the user -- NOT using sudo.  Documentation of the different VirtualBox networking types is available as Chapter 6 and full documentation of the VBoxManage CLI is available as Chapter 8 in Oracle's Documentation pages.  GNS3 uses the UDP Tunnel (Generic) type and will be demonstrated here for Intel Pro 1000 Desktop Adapters (Type 82545EM to VirtualBox).


The format of all commands is:
$VBoxManage modifyvm '<machine name>' --<option> <setting>
The options include:
  1. --nic# generic
  2. --nicpromisc# allow-all
  3. --nictype# 82545EM
  4. --cableconnected# on
  5. --nicgenericdrv# UDPTunnel
  6. --nicproperty# dest=127.0.0.1
where # = 1-8.  You may optionally set --nicproperty# sport=##### and --nicproperty# dport=##### to manually configure each NICs source and destination UDP port numbers, however, VirtualBox will automatically assign them and it is easier (and more reliable) to allow the application to do so.

VBoxManage Script for Adding Eight NICs

As described above, configuring eight NICs from the command line requires 48 commands.  This is time-consuming and error prone.  The following script -- vbox_nic.sh -- may be edited by replacing the machine name Switch  as required.
VBoxManage modifyvm 'Switch' --nic1 generic
VBoxManage modifyvm 'Switch' --nicpromisc1 allow-all
VBoxManage modifyvm 'Switch' --nictype1 82545EM
VBoxManage modifyvm 'Switch' --cableconnected1 on
VBoxManage modifyvm 'Switch' --nicgenericdrv1 UDPTunnel
VBoxManage modifyvm 'Switch' --nicproperty1 dest=127.0.0.1
VBoxManage modifyvm 'Switch' --nic2 generic
VBoxManage modifyvm 'Switch' --nicpromisc2 allow-all
VBoxManage modifyvm 'Switch' --nictype2 82545EM
VBoxManage modifyvm 'Switch' --cableconnected2 on
VBoxManage modifyvm 'Switch' --nicgenericdrv2 UDPTunnel
VBoxManage modifyvm 'Switch' --nicproperty2 dest=127.0.0.1
VBoxManage modifyvm 'Switch' --nic3 generic
VBoxManage modifyvm 'Switch' --nicpromisc3 allow-all
VBoxManage modifyvm 'Switch' --nictype3 82545EM
VBoxManage modifyvm 'Switch' --cableconnected3 on
VBoxManage modifyvm 'Switch' --nicgenericdrv3 UDPTunnel
VBoxManage modifyvm 'Switch' --nicproperty3 dest=127.0.0.1
VBoxManage modifyvm 'Switch' --nic4 generic
VBoxManage modifyvm 'Switch' --nicpromisc4 allow-all
VBoxManage modifyvm 'Switch' --nictype4 82545EM
VBoxManage modifyvm 'Switch' --cableconnected4 on
VBoxManage modifyvm 'Switch' --nicgenericdrv4 UDPTunnel
VBoxManage modifyvm 'Switch' --nicproperty4 dest=127.0.0.1
VBoxManage modifyvm 'Switch' --nic5 generic
VBoxManage modifyvm 'Switch' --nicpromisc5 allow-all
VBoxManage modifyvm 'Switch' --nictype5 82545EM
VBoxManage modifyvm 'Switch' --cableconnected5 on
VBoxManage modifyvm 'Switch' --nicgenericdrv5 UDPTunnel
VBoxManage modifyvm 'Switch' --nicproperty5 dest=127.0.0.1
VBoxManage modifyvm 'Switch' --nic6 generic
VBoxManage modifyvm 'Switch' --nicpromisc6 allow-all
VBoxManage modifyvm 'Switch' --nictype6 82545EM
VBoxManage modifyvm 'Switch' --cableconnected6 on
VBoxManage modifyvm 'Switch' --nicgenericdrv6 UDPTunnel
VBoxManage modifyvm 'Switch' --nicproperty6 dest=127.0.0.1
VBoxManage modifyvm 'Switch' --nic7 generic
VBoxManage modifyvm 'Switch' --nicpromisc7 allow-all
VBoxManage modifyvm 'Switch' --nictype7 82545EM
VBoxManage modifyvm 'Switch' --cableconnected7 on
VBoxManage modifyvm 'Switch' --nicgenericdrv7 UDPTunnel
VBoxManage modifyvm 'Switch' --nicproperty7 dest=127.0.0.1
VBoxManage modifyvm 'Switch' --nic8 generic
VBoxManage modifyvm 'Switch' --nicpromisc8 allow-all
VBoxManage modifyvm 'Switch' --nictype8 82545EM
VBoxManage modifyvm 'Switch' --cableconnected8 on
VBoxManage modifyvm 'Switch' --nicgenericdrv8 UDPTunnel
VBoxManage modifyvm 'Switch' --nicproperty8 dest=127.0.0.1
Once the script is run, the additional adapters will appear in the Network Section of the VirtualBox Manager GUI, but will not be available as tab under the machines settings.  When booted, the adapters are available to the machine.



No comments :

Post a Comment