I fixed a few other things: the static network now get properly restarted will not kill blindly all dhcp clients ... only the instance running on eth0
will only set sysctl options if they are avalible #!/bin/sh [ -f /proc/sys/net/ipv4/ip_forward ] && sysctl -w net.ipv4.ip_forward=1 [ -f /proc/sys/dev/rtc/max-user-freq ] && \ sysctl -w dev.rtc.max-user-freq=1024 if [ $(ifconfig |grep "Link encap" |grep -c "^br0") -lt 1 ] then if [ $(ps -eo pid,cmd |grep -v grep |grep dhcpcd |grep -c eth0) -ge 1 ] then RESTART_NET="dhcpcd -t 10 br0" kill -9 $(ps -eo pid,cmd |grep -v grep |grep dhcpcd |grep eth0 |awk '{print $1}') else RESTART_NET="ifconfig br0 $(ip addr show dev eth0 |grep inet |awk '{print $2}')" ifconfig eth0 0.0.0.0 down fi brctl addbr br0 brctl stp br0 off brctl setfd br0 1 brctl addif br0 eth0 $RESTART_NET fi /sbin/ifconfig $1 0.0.0.0 promisc up /sbin/brctl addif br0 $1 sleep 1 brctl show --- Ven 29/4/11, John O'Donnell <unixjohn1...@gmail.com> ha scritto: > Da: John O'Donnell <unixjohn1...@gmail.com> > Oggetto: Re: [ARMedslack] qemu-network-tun.sh modified script > A: "Slackware ARM port" <armedslack@lists.armedslack.org> > Data: Venerdì 29 Aprile 2011, 10:23 > On 04/29/2011 04:06 AM, Davide > wrote: > > If anyone else finds this handy this works with dhcp > client on both host and guest and also gets rid of all > rc.local requirements. > > On the guest os you will need to config interface once > system is up (static or via dhcp) > > Needs fixing for static ip reconfiguration/rerouting > on host system after bridge creation. > > > > I apologize for my non standard indentation ... > > Also if anyone cares, I wrote a script like that over a > year ago to lanuch a private network for many VMs (all Linux > distros - many versions) to compile software for a company I > was at. It is configured a private network so some > assembly is required. But I made most of it > configurable up top so it could be on a public > adapter. I developed it on Slack (of course) then > deployed it to a Suse production box. I had set up NFS > on the host with the source code. The source would get > copied to its own branch for the machine it was compiling > for, fire up the VM, compile over NFS, create package on NFS > host (rpm/tgz/txz/deb/etc), then die, rinse and repeat. > > #!/bin/sh > # Start/stop qemu's private network > # Revised: 12/16/2009 JJO > ### BEGIN INIT INFO > # Provides: qemunet > # Required-Start: $network > # Required-Stop: $network > # Default-Start: 3 5 > # Default-Stop: 0 1 2 6 > # Description: Start the qemu private network > ### END INIT INFO > > ETHIP=10.10.10.1 > GATEWAY= > ETHBC=10.10.10.255 > BRIDGE=br0 > ETH=dummy0 > TAP=tap0 > > # A little SuSE sanity check > [ -f /etc/SuSE-release ] && /sbin/rmmod dummy0 > >/dev/null 2>&1 > > # Start the qemu private network > qemunet_start() { > # Make sure the qemu private network isnt already > running > PROBLEM=FALSE > for IF in $ETH $TAP $BRIDGE; do > /sbin/ifconfig | grep $IF >/dev/null > 2>&1 > [ $? = 0 ] && PROBLEM=TRUE > done > if [ $PROBLEM = TRUE ]; then > echo "All or part of the qemu private network > is already running!" > echo "Cowardly refusing to start it > again! BYE!" > exit 1 > fi > > echo "Starting the qemu private network..." > # Make sure the kernel module is loaded > /sbin/lsmod | grep dummy >/dev/null 2>&1 > [ $? = 1 ] && /sbin/modprobe dummy > > # First take interface down, then bring it up with > IP 0.0.0.0 > /sbin/ifconfig $ETH down > /sbin/ifconfig $ETH 0.0.0.0 promisc up > > # Bring up the tap device (name specified as first > argument, by QEMU) > /usr/sbin/openvpn --mktun --dev $TAP > /sbin/ifconfig $TAP 0.0.0.0 promisc up > > # create the bridge between eth0 and the tap device > /sbin/brctl addbr $BRIDGE > /sbin/brctl addif $BRIDGE $ETH > /sbin/brctl addif $BRIDGE $TAP > # only a single bridge so loops are not possible, > turn off spanning tree protocol > /sbin/brctl stp $BRIDGE off > > # Bring up the bridge with ETHIP and add the default > route > /sbin/ifconfig br0 $ETHIP netmask 255.255.255.0 > broadcast $ETHBC > [ -n "$GATEWAY" ] && /sbin/route add default > gw $GATEWAY > } > > # Stop the qemu private network > qemunet_stop() { > echo "Stopping the qemu private network..." > # Bring down interface and br0 > /sbin/ifconfig $ETH down > /sbin/ifconfig $BRIDGE down > /sbin/rmmod dummy > > # Delete the bridge > /sbin/brctl delbr $BRIDGE > > # delete the tap device > /usr/sbin/openvpn --rmtun --dev $TAP > } > > # Restart the qemu private network > qemunet_restart() { > qemunet_stop > sleep 1 > qemunet_start > } > > # Check if the qemu private network is up and running > qemunet_status() { > echo -n "Checking the qemu private network: " > > # Check the qemu private inetwork > for IF in $ETH $TAP $BRIDGE; do > /sbin/ifconfig | grep $IF >/dev/null > 2>&1 > if [ $? = 1 ]; then > echo -n "$IF is down" > else > echo -n "$IF is up" > fi > if [ $IF = $BRIDGE ]; then > echo "." > else > echo -n ", " > fi > done > } > > case "$1" in > 'start') qemunet_start ;; > 'stop') qemunet_stop ;; > 'restart') qemunet_restart ;; > 'status') qemunet_status ;; > *) echo "usage $0 start|stop|restart|status" > esac > > -- === Never ask a geek why, just nod your head and slowly > back away.=== > +================================+==================================+ > | John O'Donnell > | > > | > | (Sr. Systems Engineer, > | http://juanisan.homeip.net > | > | Net Admin, Programmer, etc.) | E-Mail: > unixjohn1...@gmail.com > | > +================================+==================================+ > No man is useless who has a friend, and if we are loved we > are > indispensable. -- Robert Louis Stevenson > _______________________________________________ > ARMedslack mailing list > ARMedslack@lists.armedslack.org > http://lists.armedslack.org/mailman/listinfo/armedslack > _______________________________________________ ARMedslack mailing list ARMedslack@lists.armedslack.org http://lists.armedslack.org/mailman/listinfo/armedslack