XEN: Bridged Network Routing Issues

My current XEN installation has some unconventional setup. On my new root server I have to use routed network setup / script since I need to provide the default gateway for my assigned subnet to my XEN guests by myown.

In a common scenario, where each guest gets his own Public IP, this might not be a problem. In my case there was a need for a secondary private network where I would add proxied hosts (i.e. one for java applications proxied by apache).

Unfortunately the network scripts shipped with XEN 3.1.0 does not provide any out of the box support for such setup. So here is what I have hacked:

  • dom-0 gets a eth0:1 NIC alias set to 192.168.1.1
  • dom-u gets eth0 with a public IP and eth1: a private one like 192.168.1.100 (it's very important to include both of the ip addresses in the guest-configuration file!)

to enable routing you need to patch the vif-route script in order to get your private network routed properly.

Replace:

  1. if [ "${ip}" ] ; then
  2. for addr in ${ip} ; do
  3. ${cmdprefix} ip route ${ipcmd} ${addr} dev ${vif} src ${main_ip}
  4. done
  5. fi

With:

  1. if [ "${ip}" ] ; then
  2. for addr in ${ip} ; do
  3.  
  4. base=${ip:0:3}
  5. route_ip=${main_ip}
  6.  
  7. if [ "$base" = "192" ]
  8. then
  9. echo "private ip detected, ${ip}" >> /xen-debug
  10. route_ip="192.168.1.1"
  11. else
  12. echo "public ip detected, ${ip}" >> /xen-debug
  13. fi
  14.  
  15. ${cmdprefix} ip route ${ipcmd} ${addr} dev ${vif} src ${route_ip}
  16. echo "${cmdprefix} ip route ${ipcmd} ${addr} dev ${vif} src ${route_ip}" >> /xen-debug
  17. done
  18. fi

Not pretty, but it will do. The hardcoded eth0:1 IP address could be obtained from the ifconfig / IP output.

Actually I did not modify the original /etc/xen/scripts/vif-bridge script but did copy that one and add here the custom patches. Don't forget to change the (vif-script ...) in the main XEN config so it points to the new custom script.