Advertisement
SkipIfEqual

start_qemu_networking.sh

Aug 4th, 2011
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 3.30 KB | None | 0 0
  1. #!/bin/sh
  2. #
  3. #   Scrict basic code was taken from http://en.wikibooks.org/wiki/QEMU/Networking and modified.
  4. #   All copyrights belong to the original authors of the wikibooks article
  5. #
  6. #       script to bring up the tun device in QEMU in bridged mode
  7. #       first parameter is name of tap device (e.g. tap0)
  8. #       second parameter is the name of the user that runs the script
  9. #
  10. #
  11. #       Redistribution and use in source and binary forms, with or without
  12. #       modification, are permitted provided that the following conditions are
  13. #       met:
  14. #      
  15. #       * Redistributions of source code must retain the above copyright
  16. #         notice, this list of conditions and the following disclaimer.
  17. #       * Redistributions in binary form must reproduce the above
  18. #         copyright notice, this list of conditions and the following disclaimer
  19. #         in the documentation and/or other materials provided with the
  20. #         distribution.
  21. #       * Neither the name of the authors nor the names of its
  22. #         contributors may be used to endorse or promote products derived from
  23. #         this software without specific prior written permission.
  24. #      
  25. #       THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  26. #       "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  27. #       LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  28. #       A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  29. #       OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  30. #       SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  31. #       LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  32. #       DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  33. #       THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  34. #       (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  35. #       OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  36. #      
  37.  
  38. echo "0/6.    START QEMU NETWORK CONNECTION ----- ----- ----- ----- ----- START QEMU NETWORK CONNECTION"
  39. sbinPath=/usr/sbin
  40. #
  41. # First take eth0 down, then bring it up with IP 0.0.0.0
  42. #
  43. echo "1/6.    First take eth0 down, then bring it up with IP 0.0.0.0 "
  44. ifconfig eth0 down
  45. ifconfig eth0 0.0.0.0 promisc up
  46. #
  47. # Bring up the tap device (name specified as first argument, by QEMU)
  48. #
  49. echo "2/6.    Bring up the tap device $1 for the user $2"
  50. ${sbinPath}/openvpn --mktun --dev $1 --user $2
  51. ifconfig $1 0.0.0.0 promisc up
  52. #
  53. # create the bridge between eth0 and the tap device
  54. #
  55. echo "3/6.    Create the bridge between eth0 and the tap device"
  56. ${sbinPath}/brctl addbr br0
  57. ${sbinPath}/brctl addif br0 eth0
  58. ${sbinPath}/brctl addif br0 $1
  59. #
  60. # only a single bridge so loops are not possible, turn off spanning tree protocol
  61. #
  62. echo "4/6.    Only a single bridge so loops are not possible, turn off spanning tree protocol"
  63. ${sbinPath}/brctl stp br0 off
  64. #
  65. # Bring up the bridge with dhclient
  66. #
  67. echo "5/6.    Bring up the bridge with dhclient (this may take a few seconds..)"
  68. #dhclient -r br0
  69. dhclient br0
  70. #
  71. # stop firewall - comment this out if you don't use Firestarter ... disabled
  72. #
  73. #/sbin/service firestarter stop
  74. echo "6/6.    FINISHED ----- ----- ----- ----- ----- ----- ----- ----- FINISHED"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement