Adding virtual interfaces (not VLAN) in linux

iplinuxnetworkingvirtual machinevirtualbox

for some software testing, I need 12 different IP addresses to contact, each one with a unique MAC address.
I just set up an Arch Linux VM but I can't figure out, how to configure virtual network interfaces all pointing to the same (virtual) ethernet port.

Is this even possible?

Best Answer

You can do this through setting up ethernet bridge. You are effectively setting up a virtual switch/router, and add as many taps/ports as you desire.

I have had the following script setup for running a number of VM in a isolated network. Hope it can be useful to you:

USER=username
NUMBER_OF_VM=4
BR_NAME=vbr
IP_RANGE=10.1.1.1/24
IP_ROUTE=10.1.1.0/24

# Creates a new instance of the ethernet bridge
echo "Creating bridge: $BR_NAME"
brctl addbr $BR_NAME
# Activate the bridge
ip link set up dev $BR_NAME

# Create persistent TAPs and attach to bridge
echo "Creating $NUMBER_OF_VM tap(s) to attach to the $BR_NAME bridge"
NB=0
while [ $NB -lt $NUMBER_OF_VM ]
do
   tunctl -t vbxtap$NB -u $USER
   ip link set up dev vbxtap$NB
   brctl addif $BR_NAME vbxtap$NB
   let NB=$NB+1
done

# Assign ip address and routing to the bridge interface
echo "Assign $IP_RANGE to $BR_NAME"
ip addr add $IP_RANGE dev $BR_NAME
#echo "Assign routing rule $IP_ROUTE to $BR_NAME"
#ip route add $IP_ROUTE dev $BR_NAME