Both sides previous revisionPrevious revisionNext revision | Previous revision |
slackware:vde [2006/04/11 07:28] – alien | slackware:vde [2007/11/30 21:42] (current) – fix qemu 'macaddr' syntax; fix rc.vdenetwork script alien |
---|
| |
Dnsmasq will pick up any existing network configuration information of your computer, by reading ''/etc/hosts'' and ''/etc/resolv.conf'' and will use that information when it sends DHCP configuration to the QEMU Guest. If your computer has a functioning network connection to the LAN and/or the Internet, your QEMU Guest(s) will enjoy the same functionality. Furthermore, by examining your computer's message log ''/var/log/messages'' you will be able to determine what IP address the QEMU Guest picks up, and you can use that knowledge to ''ssh'' into the Virtual Machine or point a web browser to a running Apache server inside the VM - or connect to whatever other network service that you enabled on your VM. | Dnsmasq will pick up any existing network configuration information of your computer, by reading ''/etc/hosts'' and ''/etc/resolv.conf'' and will use that information when it sends DHCP configuration to the QEMU Guest. If your computer has a functioning network connection to the LAN and/or the Internet, your QEMU Guest(s) will enjoy the same functionality. Furthermore, by examining your computer's message log ''/var/log/messages'' you will be able to determine what IP address the QEMU Guest picks up, and you can use that knowledge to ''ssh'' into the Virtual Machine or point a web browser to a running Apache server inside the VM - or connect to whatever other network service that you enabled on your VM. |
| |
| |
====Tying it all together ==== | ====Tying it all together ==== |
=== How it works === | === How it works === |
| |
* First of all, we load the "tun" driver which is a kernel module that you should have enabled for your kernel. Slackware kernels have this tun module, if you compile your own kernels, make sure you configure<code>CONFIG_TUN=m</code> or <code>CONFIG_TUN=y</code>. Also, the device ''/dev/net/tun'' needs to exist. On my Slackware system it is created automatically when I run <code>modprobe tun</code> (or let the ''rc.vdenetwork'' init script below load the module). If your system does not automatically create that device file, you should create it yourself: <code> | * First of all, we load the "tun" driver which is a kernel module that you should have enabled for your kernel. Slackware kernels have this tun module, if you compile your own kernels, make sure you configure<code> |
| CONFIG_TUN=m (Device Drivers - Network device support -> Universal TUN/TAP device driver support) |
| CONFIG_IP_NF_CONNTRACK=m (Connection tracking) |
| CONFIG_IP_NF_IPTABLES=m (IP tables support) |
| CONFIG_IP_NF_NAT=m (Full NAT)</code> Instead of building these as modules, you can of course compile them into the kernel by changing the 'm' to 'y'. Also, the device ''/dev/net/tun'' needs to exist. On my Slackware system it is created automatically when I run <code>modprobe tun</code> (or let the ''rc.vdenetwork'' init script below load the module). If your system does not automatically create that device file, you should create it yourself: <code> |
mkdir /dev/net | mkdir /dev/net |
mknod /dev/net/tun c 10 200 | mknod /dev/net/tun c 10 200 |
</code> The TCPIP configuration values I used in this example are arbitrary - you may choose whatever you like, as long as you pick an address within a subnet range that is not used on your local network. The Virtual Machines you are going to be running will all be in the IP subnet defined by the //tap0//'s IP address and netmask. The tap0 will act as the default gateway for that subnet. | </code> The TCPIP configuration values I used in this example are arbitrary - you may choose whatever you like, as long as you pick an address within a subnet range that is not used on your local network. The Virtual Machines you are going to be running will all be in the IP subnet defined by the //tap0//'s IP address and netmask. The tap0 will act as the default gateway for that subnet. |
| |
* Traffic to and from the subnet behind the tap0 interface must be forwarded of course - <code> | * Traffic to and from the subnet behind the tap0 interface must be forwarded <code> |
echo "1" > /proc/sys/net/ipv4/ip_forward | echo "1" > /proc/sys/net/ipv4/ip_forward |
</code> and since we are most probably setting up all of this on an ordinary workstation, we don't want to cause network disruption by suddenly announcing the birth of a new network segment. We will "hide" the tap0 interface and our QEMU/VDE subnet behind a firewall, by applying couple of NAT //iptables// rules. Tus, we designate the eth0 interface as the external firewall interface (in the example I use //eth0// - your external interface might be called different). <code> | </code> and since we are most probably setting up all of this on an ordinary workstation, we don't want to cause network disruption by suddenly announcing the birth of a new network segment. We will "hide" the tap0 interface and our QEMU/VDE subnet behind a firewall, by applying couple of NAT //iptables// rules. Tus, we designate the eth0 interface as the external firewall interface (in the example I use //eth0// - your external interface might be called different). <code> |
/etc/rc.d/rc.vdenetwork start | /etc/rc.d/rc.vdenetwork start |
</code> We're all set! It is time to start your QEMU session and see if it all works as expected! I have provided another script in the [[#example_scripts | last section]] of this article as an example of how to run QEMU and have it using VDE for the networking. | </code> We're all set! It is time to start your QEMU session and see if it all works as expected! I have provided another script in the [[#example_scripts | last section]] of this article as an example of how to run QEMU and have it using VDE for the networking. |
| |
| |
| |
echo -n "Starting VDE network for QEMU: " | echo -n "Starting VDE network for QEMU: " |
| |
# If we are running 2.6, load tun module | # Load tun module |
if uname -r | grep '^2.6'; then | /sbin/modprobe tun 2>/dev/null |
/sbin/modprobe tun 2>/dev/null | # Wait for the module to be loaded |
# Wait for the module to be loaded | while ! /bin/lsmod |grep -q "^tun"; do echo Waiting for tun device;sleep 1; done |
while ! /bin/lsmod |grep -q "^tun"; do echo Waiting for tun device;sleep 1; done | |
fi | |
| |
# Start tap switch | # Start tap switch |
# Remove the control socket | # Remove the control socket |
rm -f /tmp/vde.* | rm -f /tmp/vde.* |
| rmdir /var/run/vde.ctl |
# Stop dnsmasq | # Stop dnsmasq |
pgrep -f dnsmasq | xargs kill -TERM | pgrep -f dnsmasq | xargs kill -TERM |
restart|reload) | restart|reload) |
$0 stop | $0 stop |
| sleep 1 |
$0 start | $0 start |
;; | ;; |
| |
# This command returns to the command prompt immediately, | # This command returns to the command prompt immediately, |
# and QEMU's error output is redirected to files. | # and QEMU's (error) output is redirected to logfiles. |
vdeqemu -net vde,vlan=0 -net nic,vlan=0,macaddr 52:54:00:00:EE:02 -m 256 -localtime -soundhw all -hda winxp.img -cdrom ${ISODIR}/winxp_pro_us.iso 1>winxp.log 2>winxp.err ${PARAMS} & | vdeqemu -net vde,vlan=0 -net nic,vlan=0,macaddr=52:54:00:00:EE:02 -m 256 -localtime -soundhw all -hda winxp.img -cdrom ${ISODIR}/winxp_pro_us.iso 1>winxp.log 2>winxp.err ${PARAMS} & |
</code> | </code> |
| |