blob: da815f6b20da13ffa688ab26b43ee63fb6c53d42 (
about) (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
|
#!/bin/sh
# $Id$
# Qemu environment preparation script
# ---------------------------------------------------------------------------
#
# After running this startup script, run a QEMU virtual machine in this way:
#
# vdeqemu [qemu_option [qemu_option], ...]
#
# The vdeqemu program will automatically connect
# the QEMU virtual machine to the VDE switch.
#
# ---------------------------------------------------------------------------
# The IP configuration for the tap device that will be used for
# the virtual machine network:
TAP_DEV=tap0
TAP_IP=10.111.111.254
TAP_MASK=255.255.255.0
TAP_BCAST=`/bin/ipmask ${TAP_MASK} ${TAP_IP} | cut -f 1 -d ' '`
# Host interfaces that need to be NAT-ed (in case we're not bridging):
# Add more interfaces space-separated, like "eth+ wlan+"
NAT_IFS="eth+"
# Definitions for the LAN segment the Qemu virtual machines will be in.
# These definitions will be fed to dnsmasq - this program will provide DNS
# and DHCP to the Qemu LAN.
# The VM_IPLOW and VM_IPHIGH addresses must agree with the definitions for
# the tap0 device above. These 'low' and 'high' values are the IP address
# range for the DHCP server to use.
VM_DOMAIN=qemu.lan
VM_IPLOW=10.111.111.128
VM_IPHIGH=10.111.111.199
VM_BCAST=${TAP_BCAST}
VM_MASK=${TAP_MASK}
# For additional options to dnsmasq - the commented example specifies that all DNS lookups
# for 'my.net' should go to 192.168.1.1; and on the second line you find a configuration
# for supporting network boot:
#DNSMASQ_OPTIONS="--server /my.net/192.168.1.1 \
# --dhcp-boot=/pxelinux.0,\"192.168.1.1\",192.168.1.1"
DNSMASQ_OPTIONS=""
# See how we were called.
case "$1" in
start)
echo -n "Starting VDE network for QEMU: "
# Load tun module
/sbin/modprobe tun 2>/dev/null
# Wait for the module to be loaded
while ! /bin/lsmod |grep -q "^tun"; do echo Waiting for tun device;sleep 1; done
# Start tap switch
vde_switch -tap ${TAP_DEV} -daemon
sleep 1
# Bring tap interface up
ifconfig ${TAP_DEV} ${TAP_IP} broadcast ${TAP_BCAST} netmask ${TAP_MASK}
# Start IP Forwarding
echo "1" > /proc/sys/net/ipv4/ip_forward
for NIC in ${NAT_IFS}; do
iptables -t nat -A POSTROUTING -o ${NIC} -j MASQUERADE
done
# Change pipe permission (vde2 uses a different pipe directory)
#chmod 666 /tmp/vde.ctl
chmod -R a+rwx /var/run/vde.ctl
# If we are not running 2.6, apply workaround
if uname -r | grep '^2.4'; then
echo 1024 > /proc/sys/dev/rtc/max-user-freq
fi
# Start dnsmasq, the DNS/DHCP server
# for our Virtual Machines behind the tap0 interface
/usr/sbin/dnsmasq \
--log-queries \
--user=daemon \
--dhcp-leasefile=/var/state/dhcp/qemu-dhcpd.leases \
--dhcp-range=${VM_IPLOW},${VM_IPHIGH},${VM_MASK},${VM_BCAST},8h \
--interface=${TAP_DEV} \
--domain=${VM_DOMAIN} \
$DNSMASQ_OPTIONS
echo
;;
stop)
echo -n "Stopping VDE network for QEMU: "
{
# Delete the NAT rules
for NIC in ${NAT_IFS}; do
iptables -t nat -D POSTROUTING -o ${NIC} -j MASQUERADE
done
# Bring tap interface down
ifconfig ${TAP_DEV} down
# Kill VDE switch
pgrep -f vde_switch | xargs kill -TERM
# Remove the control socket (vde2 uses a different location)
#rm -f /tmp/vde.ctl
rmdir /var/run/vde.ctl
# Stop dnsmasq
pgrep -f dnsmasq | xargs kill -TERM
} >/dev/null 2>&1
echo
;;
restart|reload)
$0 stop
sleep 1
$0 start
;;
*)
echo "Usage: $0 {start|stop|restart|reload}"
exit 1
esac
|