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

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.

Get the latest tutorials on SysAdmin, Linux/Unix, Open Source, and DevOps topics:
CategoryList of Unix and Linux commands
File Management cat
Firewall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network Utilities dig host ip nmap
OpenVPN CentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Manager apk apt
Processes Management bg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searching grep whereis which
User Information groups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPN CentOS 8 Debian 10 Firewall Ubuntu 20.04
3 comments… add one
  • Gregory Hood Jul 4, 2009 @ 19:19

    I need help creating a shell script using ping. I need it to check the network and see if its up every 5 mins. If the script finds the network up, I want it to go back to sleep. However if it finds the network down to check it 3 times in 5 min intervals. By the third check, if the the network is still down to shutdown the server.
    *I am running AIX 5.3

  • vivek Dec 5, 2008 @ 19:40

    Gael,

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

  • Gael Dec 2, 2008 @ 22:09

    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

Leave a Reply

Your email address will not be published. Required fields are marked *

Use HTML <pre>...</pre>, <code>...</code> and <kbd>...</kbd> for code samples.