Wednesday 28 August 2013

Adding multiple network adapters to linux guest virtual machine (VirtualBox or VMware)

Title: Adding multiple network adapters (NIS | network interfaces) to linux guest virtual machine (VirtualBox or VMware)

I came across a situation where I would like to have dual network interfaces in a CentOS guest virtual machine so that the VM can have dual IP addresses.

I have figured out the way to achieve this in CentOS, but this can be easily extended to other type of Linux boxes. This is done in Oracle VirtualBox, but it would be very similar if you use VMware tools.

Meanwhile, I only tried Bridged Adapter. But it should be similar if you use NAT.

1. Add a virtual network adapter in Oracle VirtualBox:


2. Reboot the VM.

3. Go to /etc/sysconfig/network-scripts/. You will see ifcfg-eth0 only, because the config script for the extra network cards are not created automatically. Now you need to manually create the script for the 2nd network card (NIC, network interface, network adapter, whatever you prefer to call it).

4. cp ifcfg-eth0 ifcfg-eth1 . Now you can edit ifcfg-eth1 to contain the values. Take a look at this file first.
DEVICE=eth0
TYPE=Ethernet
UUID=3b594564-4088-4gfd-a4a6-5462e7b3fbde
ONBOOT=yes
NM_CONTROLLED=yes
BOOTPROTO=dhcp
HWADDR=08:00:12:53:62:CD
DEFROUTE=yes
PEERDNS=yes
PEERROUTES=yes
IPV4_FAILURE_FATAL=yes
IPV6INIT=no
NAME="System eth0"


4 lines to change:
DEVICE; UUID;  HWADDR;  NAME

DEVICE: increment the device ID so that it looks like this:

DEVICE=eth1

UUID: a utility called uuidgen can generate UUIDs, and this is not limited to network adapters. Use the output to revise the UUID line.


HWADDR: this is the MAC address of the network card. There are at least 3 places you can find the MAC address.
(1) when you enabled the network card in Oracle VirtualBox, the MAC address has been created, you can see this address in the picture above, see "MAC Address".
(2) Run command ip link show, you will see the list of network interfaces.
(3) Go to /sys/class/net/eth1, the MAC address for eth1 is held in the file 'address'.
Now you have this information, you can update this line.

NAME: increment the number accordingly. In this case it will be  "System eth1" .

5. Restart the network service: sudo service network restart
You should see both NIC get started successfully.
Bringing up loopback interface: [ OK ]
Bringing up interface eth0:
Determining IP information for eth0... done.   [ OK ]
Bringing up interface eth1:
Determining IP information for eth1... done.   [ OK ]


If error, trouble shoot. You might have a typo somewhere.


Note that I am using DHCP in my case, you might need to adjust the network scripts accordingly if you need static address. There are plenty of tutorials on setting up static IP.


No comments:

Post a Comment