<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>The Exploits of Plouj &#187; TUN</title>
	<atom:link href="http://www.plouj.com/blog/tag/tun/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.plouj.com/blog</link>
	<description>A blog by Michael Ploujnikov</description>
	<lastBuildDate>Wed, 01 Sep 2010 17:05:46 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>TAP that DHCP bridge for some Qemu TUN in Fedora</title>
		<link>http://www.plouj.com/blog/2008/07/29/tap-that-dhcp-bridge-for-some-qemu-tun-in-fedora/</link>
		<comments>http://www.plouj.com/blog/2008/07/29/tap-that-dhcp-bridge-for-some-qemu-tun-in-fedora/#comments</comments>
		<pubDate>Tue, 29 Jul 2008 23:22:40 +0000</pubDate>
		<dc:creator>plouj</dc:creator>
				<category><![CDATA[HOWTO]]></category>
		<category><![CDATA[bridge]]></category>
		<category><![CDATA[DHCP]]></category>
		<category><![CDATA[fedora]]></category>
		<category><![CDATA[GNU/Linux]]></category>
		<category><![CDATA[hacks]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[networking]]></category>
		<category><![CDATA[Qemu]]></category>
		<category><![CDATA[Redhat]]></category>
		<category><![CDATA[sysconfig]]></category>
		<category><![CDATA[TAP]]></category>
		<category><![CDATA[TUN]]></category>

		<guid isPermaLink="false">http://www.plouj.com/blog/?p=20</guid>
		<description><![CDATA[The other day I needed to setup bridged networking for a Qemu virtual machine. Although I found a rather well written generic TAP interfaces guide on Wikibooks. It only explained how to configure a network bridge on a host machine with a static IP. I wanted to do this on a host that used DHCP. [...]]]></description>
			<content:encoded><![CDATA[<p>The other day I needed to setup bridged networking for a Qemu virtual machine. Although I found a rather well written generic <a href="http://en.wikibooks.org/wiki/QEMU/Networking#TAP_interfaces">TAP interfaces guide on Wikibooks</a>. It only explained how to configure a network bridge on a host machine with a static IP. I wanted to do this on a host that used DHCP. Plus I wanted to keep all configuration in Fedora specific places. Having discovered a good way to do this through experimentation after a few fruitless Google searches I thought it would be useful for myself and others to have the configuration documented here.</p>
<h2>ifcfg-eth0</h2>
<p>First, I changed the host&#8217;s (auto-generated) <code>/etc/sysconfig/network-scripts/ifcfg-eth0</code> script from this:</p>
<pre># Attansic Technology Corp. L1 Gigabit Ethernet Adapter
DEVICE=eth0
BOOTPROTO=dhcp
HWADDR=00:1D:60:35:A7:64
ONBOOT=yes</pre>
<p>to this:</p>
<pre># Attansic Technology Corp. L1 Gigabit Ethernet Adapter
DEVICE=eth0
TYPE=Ethernet
BRIDGE=br0
ONBOOT=yes</pre>
<p>This turns off DHCP on the physical Ethernet device and just specifies that it will be connected to or a part of a bridge.</p>
<h2>ifcfg-br0</h2>
<p>Second, I created <code>/etc/sysconfig/network-scripts/ifcfg-br0</code>, which will be called to setup a bridge device:</p>
<pre>DEVICE=br0
TYPE=Bridge
BOOTPROTO=dhcp
HWADDR=00:1D:60:35:A7:64
ONBOOT=yes
DELAY=0
STP=off</pre>
<p>As you can see, most of this configuration is copied from eth0 plus the bridge configuration as per the Qemu Wikibook.</p>
<h2>qemu-ifup/down</h2>
<p>Third, I shortened the <code>/etc/qemu-ifup</code> and <code>/etc/qemu-ifdown</code> from Wikibooks to get this:</p>
<p><em>/etc/qemu-ifup:</em></p>
<pre>#!/bin/sh
USER=$(id -un)
sudo /usr/sbin/openvpn --mktun --dev $1 --user "$USER"
sudo /sbin/ifconfig $1 0.0.0.0 promisc up
sudo /usr/sbin/brctl addif br0 $1</pre>
<p><em>/etc/qemu-ifdown:</em></p>
<pre>#!/bin/sh
sudo /sbin/ifconfig $1 down
sudo /usr/sbin/brctl delif br0 $1
sudo /usr/sbin/openvpn --rmtun --dev $1</pre>
<p>Here I basically removed all of the configuration that is taken care of in the sysconfig scripts. I also made explicit use of sudo simply because that is my preference.</p>
<h2>Final steps</h2>
<p>Now I can simply run <code>/etc/qemu-ifup tap0</code> once to create a TAP device, and use something like: <code>qemu-kvm -hda /virtual-machines/fedora9.disk -m 512 -net nic -net tap,ifname=tap0,script=no</code> to start a virtual machine. When I&#8217;m done running the virtual machine, I can run <code>/etc/qemu-ifdown tap0</code> to remove the TAP device.</p>
<p>All this sounds simple now that it&#8217;s working, but initially it took a lot of guessing on my part so I&#8217;m documenting it here for the future.</p>
<p>I would appreciate it if someone can point me to the official Redhat/Fedora documentation on editing <code>/etc/sysconfig/network-scripts/</code> scripts.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.plouj.com/blog/2008/07/29/tap-that-dhcp-bridge-for-some-qemu-tun-in-fedora/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>
