Saturday, July 9, 2011

Multiple VLAN's with Xen Dom0

​A great feature of Linux and Xen is the ability to run DomU’s on multiple networks. To do this we first need to set up the VLAN’s on a switch and then set the port the Dom0 is connected to allow for 802.1q traffic. On a Cisco switch, log into the IOS and change the interface that the server is sitting on and type:
switch(config-if) switchport trunk encapsulation dot1q
switch(config-if) switchport mode trunk
Once this is done we can then configure Dom0 to communicate to these networks. In CentOS, you need to change directories to /etc/sysconfig/network-scripts.
First copy the ifcfg-eth0 file to make a back up then edit the file as follows:
DEVICE=eth0
HWADDR=
ONBOOT=yes
BOOTPROTO=none
Next we create four new files which will define our VLAN and non-VLAN traffic. The first two files will define which VLANs the server should listen on:
Create the file: /etc/sysconfig/network-scripts/ifcfg-eth0.17. This will define VLAN 17.
Then enter in the following:
DEVICE=eth0.17
BOOTPROTO=static
ONBOOT=yes
VLAN=yes
TYPE=Ethernet
BRIDGE=xenbr17
Make a secondary file which will sit on VLAN 192, VLAN 192 is where the IP of the Dom0 will reside.
DEVICE=eth0.192
BOOTPROTO=static
ONBOOT=yes
VLAN=yes
TYPE=Ethernet
BRIDGE=xenbr192
The next two files will define the bridged interfaces. These are necessary to strip the 802.1q header so the server and DomU’s can communicate across the network. The first file will be for the publicly routable network:
DEVICE=xenbr17
TYPE=Bridge
BOOTPROTO=static
ONBOOT=yes
DELAY=0
STP=off
The next file will be for the internal network.
DEVICE=xenbr192
TYPE=Bridge
BOOTPROTO=static
ONBOOT=yes
DELAY=0
STP=off
IPADDR=192.168.1.12
NETMASK=255.255.255.0
NETWORK=192.168.1.0
BROADCAST=192.168.1.255
After that reboot the server.
Next create a virtual instance with virt-install and run it as follows:
virt-install --name test --ram 1024 --location 'centos mirror' -f /dev/lvm/test -b xenbr17 -p
The '-b' is important as it will define the bridge the new server will sit on.