<?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>TD Online &#187; Howto</title>
	<atom:link href="http://blog.td-online.co.uk/category/howto/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.td-online.co.uk</link>
	<description>Smile Like You Mean It</description>
	<lastBuildDate>Wed, 12 May 2010 07:46:27 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>HOWTO: Automating Bridges and TUN/TAP</title>
		<link>http://blog.td-online.co.uk/2008/07/10/howto-automating-bridges-and-tuntap/</link>
		<comments>http://blog.td-online.co.uk/2008/07/10/howto-automating-bridges-and-tuntap/#comments</comments>
		<pubDate>Thu, 10 Jul 2008 21:02:27 +0000</pubDate>
		<dc:creator>TD</dc:creator>
				<category><![CDATA[Articles]]></category>
		<category><![CDATA[FOSS]]></category>
		<category><![CDATA[Howto]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[networking]]></category>
		<category><![CDATA[simple]]></category>
		<category><![CDATA[ubuntu]]></category>

		<guid isPermaLink="false">http://blog.td-online.co.uk/?p=188</guid>
		<description><![CDATA[This isn&#8217;t ground-breaking stuff by any means, it&#8217;s more just a simple reminder for myself about how I did certain things in order to get a network bridge set up under Ubuntu 8.04, and to create a Tap connection that I could then use in VirtualBox to let routes and all that shiny stuff work. [...]]]></description>
			<content:encoded><![CDATA[<p>This isn&#8217;t ground-breaking stuff by any means, it&#8217;s more just a simple reminder for myself about how I did certain things in order to get a network bridge set up under Ubuntu 8.04, and to create a Tap connection that I could then use in VirtualBox to let routes and all that shiny stuff work. It doesn&#8217;t explain things fully (I don&#8217;t understand it), but it does cover what I did, hopefully step by step.<br />
This only made sense thanks to the following pages:</p>
<blockquote><p><a href="https://help.ubuntu.com/community/VirtualBox#Create%20A%20Bridge" target="_blank">1. https://help.ubuntu.com/community/VirtualBox#Create%20A%20Bridge</a><br />
<a href="http://ubuntuforums.org/showthread.php?t=830777" target="_blank">2. http://ubuntuforums.org/showthread.php?t=830777</a><br />
<a href="http://ubuntuforums.org/showthread.php?t=752127" target="_blank">3. http://ubuntuforums.org/showthread.php?t=752127</a></p></blockquote>
<p>Anyway, let&#8217;s begin.</p>
<h3>Does it Work&#8230;?</h3>
<p>First step along this Rocky Road to Near-Fail was to follow the useful advice in Link 1 above, and thus making sure that creating a bridge and activating it and the TUN/TAP actually worked. It did. From that link, I did the following:</p>
<p><code>~$ sudo aptitude install bridge-utils uml-utilities</code></p>
<p>This installs the pre-requisite applications to do the fun stuff.<br />
The second point depends on your viewpoint, but it&#8217;s probably worth backing up your current <strong>/etc/network/interfaces</strong> file in case you manage to break something:</p>
<p><code>~$ sudo cp /etc/network/interfaces /etc/network/interfaces.good</code></p>
<p>Obviously, what you call and where you place the backup is up to you. Just make sure it&#8217;s something you remember later.</p>
<p>Now for preparing the bridge itself. Fun:</p>
<p><code>~$ sudo tunctl -t tap1 -u USERNAME<br />
~$ sudo chown root.vboxusers /dev/net/tun<br />
~$ sudo chmod g+rw /dev/net/tun</code></p>
<p>Next up, we need to edit another file, apparently to help make permissions persist after reboots. The file we need to edit is <strong>/etc/udev/rules.d/20-names.rules</strong><br />
Again,  we need to edit this as root, so from the terminal:</p>
<p><code>~$ sudo [$editor_du_jour] /etc/udev/rules.d/20-names.rules</code></p>
<p>And then at the end of that file, find the following line:<br />
<code>KERNEL=="tun",                          NAME="net/%k"</code><br />
And add the following to make it look like this:<br />
<code>KERNEL=="tun",                          NAME="net/%k",  GROUP="vboxusers",     MODE="0660"</code></p>
<p>Take whichever process your editor takes for saving and closing that.</p>
<p>Now we can create the bridge itself:</p>
<p><code>~$ sudo brctl addbr br0</code></p>
<p>Now put the network interface into promiscuous mode, add it to the bridge, and set the Bridge to DHCP (<strong>if you are using DHCP</strong>, if not, ignore these and see the next statement):</p>
<p><code>~$ sudo ifconfig eth0 0.0.0.0 promisc<br />
~$ sudo brctl addif br0 eth0<br />
~$ sudo dhclient br0</code></p>
<p>If you are <strong>NOT using DHCP</strong>, and have a <strong>STATIC IP</strong>, follow this example:<br />
<code>~$ sudo ifconfig br0 192.168.1.105 netmask 255.255.0.0<br />
~$ sudo route add default gw 192.168.1.1 br0</code><br />
(Obviously, replace the IP, Netmask, and Gateway IPs with your own&#8230;)</p>
<p>Now, simply add the tap1 device to the bridge and bring up the interface:</p>
<p><code>~$ sudo brctl addif br0 tap1<br />
~$ sudo ifconfig tap1 up</code></p>
<p>Last thing I did was just to run <strong>ifconfig</strong> to double check everything that should be there is there. You should have the Bridge (<strong>br0</strong>) with your IP Address, the physical interface (<strong>eth0</strong>) set promiscuously, and the TAP, <strong>tap1</strong>.</p>
<p>Opening up VirtualBox and change the appropriate network settings for your VirtualMachine to point to the new tap device (in my case, <strong>tap1</strong>). First step in that is to change the &#8216;Attached To&#8217; drop-down to point to &#8216;Host Interface&#8217;.</p>
<p style="text-align: center;"><a href="http://blog.td-online.co.uk/wp-content/uploads/2008/07/vb-net-set.png"><img class="alignnone size-medium wp-image-189 aligncenter" title="vb-net-set" src="http://blog.td-online.co.uk/wp-content/uploads/2008/07/vb-net-set-300x283.png" alt="Screenshot of the Settings" width="300" height="283" /></a></p>
<p>Starting the VirtualMachine now should be effortless, and when it starts up (and you add them), the same routes you&#8217;ve been using should work just fine&#8230; so ping, ping away!</p>
<h3>Making it Permanent</h3>
<p>The initial instructions I was hoping to follow from Link 1 didn&#8217;t work out all too well for me, so I was back trying to work out exactly where I could fix it. Thankfully, SpaceTeddy on the <a href="http://www.ubuntuforums.org" target="_blank">Ubuntu forums</a> was able to point me in the right direction of some useful hints he&#8217;d written.<br />
In the end, I did the following.<br />
First step is to go back and edit <strong>/etc/network/interfaces</strong> with your preferred Text Editor. You need to be root to do this. In there, you are replacing your current Physical Interface settings for the bridge, or, in my case, swapping out eth0 for br0. Then you are adding a rule to tell the bridge it using your physical interface (eth0). Finally you are adding the stuff that brings eth0 up as promiscuous. It should look like this:</p>
<p><code>auto br0<br />
iface br0 inet static<br />
bridge_ports eth1<br />
auto eth1<br />
iface eth1 inet manual<br />
up ifconfig $IFACE 0.0.0.0 up<br />
up ip link set $IFACE promisc on<br />
down ip link set $IFACE promisc off<br />
down ifconfig $IFACE down</code></p>
<p>It&#8217;s probably worthwhile noting that you <em>SHOULD NOT</em> remove the references to the Loopback Interface (<strong>lo</strong>), but do make sure any other references to your physical interface are commented out, or plain old deleted &#8211; you made a backup anyway, right?</p>
<p>After doing that, the only thing left to include is finding a way to bring the TAP interface up on startup. The other guides do mention ways to do it through /etc/network/interfaces but they didn&#8217;t work for me &#8211; I still don&#8217;t know why.</p>
<p>Instead, I just added the commands to <strong>/etc/rc.local</strong>, along with the routes I need to bring up everytime I startup. This was as simple a case as opening up the file in my preferred text editor (again, <em>sudo</em> is needed) and adding the following:</p>
<p><code>tunctl -t tap1 -u MyUser<br />
brctl addif br0 tap1<br />
ifconfig tap1 up</p>
<p>exit 0</code></p>
<p>Make sure to keep the &#8216;exit 0&#8242; at the end of that file &#8211; it seems to work.</p>
<p>And that massively over-lengthy block of text is all that you need to do. I will try and refine this at some point but, this works for me and seems easy enough to follow if I need to remind myself what I did again.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.td-online.co.uk/2008/07/10/howto-automating-bridges-and-tuntap/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
