Shell Script To Bridge Multiple Network Interfaces on Xen host to Guests VPS

by Vivek Gite [Last updated: December 5, 2008]

in Networking, Virtualization

Save script as /etc/xen/scripts/network-xen-custom with the following content:

#!/bin/sh
# network-xen-custom
# Exit if anything goes wrong
set -e
 
# First arg is operation.
OP=$1
#shift
script=/etc/xen/scripts/network-bridge
case ${OP} in
        start)
                $script start vifnum=0 bridge=xenbr0 netdev=eth0
                $script start vifnum=1 bridge=xenbr1 netdev=eth1
                ;;
        stop)
                $script stop vifnum=0 bridge=xenbr0 netdev=eth0
                $script stop vifnum=1 bridge=xenbr1
br1 netdev=eth1
                ;;
        status)
                $script status vifnum=0 bridge=xenbr0 netdev=eth0
                $script status vifnum=1 bridge=xenbr1 netdev=eth1
                ;;
        *)
                echo "Unknown command:${OP}"
                echo 'Valid commands are: start, stop, status'
                exit 1
               ;;
esac

Set permissions:
# chmod 755 /etc/xen/scripts/network-xen-custom
Edit the /etc/xen/xend-config.sxp file to comment out the old script and add a line to call the new script:
#(network-script network-bridge)
(network-script network-xen-custom)

Restart the system for the new bridge interfaces to start up correctly.

Want to read Linux tips and tricks, but don't have time to check our blog everyday? Subscribe to our email newsletter to make sure you don't miss a single tip/tricks.

{ 2 comments… read them below or add one }

Gael 12.02.08 at 10:09 pm

Hi guys,

I think there is a typo in the script, in the “stop” case:

$script stop vifnum=1 bridge=xen!
br1 netdev=eth1

I think it should be:
$script stop vifnum=1 bridge=xenbr1 netdev=eth1

vivek 12.05.08 at 7:40 pm

Gael,

Thanks for the heads up. I’ve updated script.

Leave a Comment

You can use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Tagged as: , , , , ,

Previous post: Shell Script To Count Vowels, Blank Spaces, Characters, Number of line and Symbols

Next post: MySQL Drop All Tables Shell Script Utility