<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet href="/stylesheets/rss.css" type="text/css"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
  <channel>
    <title>blog@insidesystems.net: Stupid Bridge Tricks #1 - How to add more bandwidth</title>
    <link>http://blog.insidesystems.net/articles/2006/06/16/Stupid-Bridge-Tricks-1-How-to-add-more-bandwidth</link>
    <language>en-us</language>
    <ttl>40</ttl>
    <description></description>
    <item>
      <title>Stupid Bridge Tricks #1 - How to add more bandwidth</title>
      <description>&lt;p style="text-indent: 5em;"&gt;Ever been in a situation where you had one, maybe two T1 lines and it just wasn&amp;#8217;t quite enough bandwidth? Ever thought it would it be &lt;strong&gt;really&lt;/strong&gt; nice if you could just get a cheap &lt;span class="caps"&gt;DSL&lt;/span&gt; or cable account (or two) to offload some of the unexciting web and mail traffic and not have to go through the hassle of restructuring the network or even rebooting a running machine? Through the magic of &lt;a href="http://www.openbsd.org"&gt;OpenBSD&lt;/a&gt; and &lt;a href="http://www.benzedrine.cx/pf.html"&gt;PF&lt;/a&gt;, it&amp;#8217;s pretty easy.&lt;/p&gt;&lt;h2&gt;Tools&lt;/h2&gt;


	&lt;p&gt;For this exercise, we will be using &lt;a href="http://www.openbsd.org"&gt;OpenBSD 3.7&lt;/a&gt; and &lt;a href="http://www.benzedrine.cx/pf.html"&gt;PF&lt;/a&gt;. You will also need a machine with a minimum of 3 NICs (2 for the slicing and 1 per extra connection you are adding)&lt;/p&gt;


	&lt;ul&gt;
	&lt;li&gt;&lt;strong&gt;Why OpenBSD 3.7? That&amp;#8217;s really old man.&lt;/strong&gt; Yah, I know, but that is what is already installed and in production for this example. As far as I know, everything is the same with 3.9 (the current release).&lt;/li&gt;
		&lt;li&gt;&lt;strong&gt;What is it with you and PF?&lt;/strong&gt; PF is ridiculously powerful and flexible .. you have to use it for a while to really understand how magical it is compared to most other tools, but that&amp;#8217;s part of what these articles are for.&lt;/li&gt;
		&lt;li&gt;&lt;strong&gt;What about (ipf|iptables|whatever)?&lt;/strong&gt; This might be possible in those systems, I don&amp;#8217;t know. I&amp;#8217;ve never had to explore them as PF accomplished everything I&amp;#8217;ve needed it to thus far.&lt;/li&gt;
	&lt;/ul&gt;


	&lt;h2&gt;Proof of Concept&lt;/h2&gt;


	&lt;h4&gt;Phase One &amp;#8211; Slicing into the existing network&lt;/h4&gt;


	&lt;p&gt;The goal here is to make a transparent bridge that slides in between your existing network and the internet. In our case, this was between a ProCurve 4000m and a Cisco 2600 series. For physical cabling you will want to be careful .. you may need a crossover cable depending on the NICs you&amp;#8217;ve chosen and your particular equipment. Bridge setup is pretty straightforward and right out of the &lt;a href="http://www.openbsd.org/faq/faq6.html#Bridge"&gt;OpenBSD &lt;span class="caps"&gt;FAQ&lt;/span&gt;&lt;/a&gt; but I&amp;#8217;ll reproduce the steps here just for fun.&lt;/p&gt;


	&lt;p&gt;1. The interface going to the Cisco is fxp0 and we want it to have an IP so we can get to it remotely so we execute:&lt;/p&gt;


&lt;pre&gt;echo "inet 216.123.123.123 255.255.252.0 NONE" &amp;gt; /etc/hostname.fxp0&lt;/pre&gt;

	&lt;p&gt;(You will obviously want to change this to a valid IP/netmask on your local network.)&lt;/p&gt;


	&lt;p&gt;2. The interface going to the ProCurve is em1 and it needs to be up to be part of the bridge so we execute:&lt;/p&gt;


&lt;pre&gt;echo "up media auto" &amp;gt; /etc/hostname.em1&lt;/pre&gt;

	&lt;p&gt;(Again, you should pick whichever interface is going to the other device, not the one in the example)&lt;/p&gt;


	&lt;p&gt;3. Set up the bridge device for the two by editing the file &lt;code&gt;/etc/bridgename.bridge0&lt;/code&gt; with the contents:&lt;/p&gt;


&lt;pre&gt;add em1
add fxp0
up&lt;/pre&gt;

	&lt;p&gt;(The order of the first two don&amp;#8217;t matter, but up must be last as the startup scripts execute each line in turn.)&lt;/p&gt;


	&lt;p&gt;4. Enable forwarding of packets by uncommenting the following line in &lt;code&gt;/etc/sysctl.conf&lt;/code&gt;:&lt;/p&gt;


&lt;pre&gt;net.inet.ip.forwarding=1&lt;/pre&gt;

	&lt;p&gt;(You should look through some of these just for fun, you can encrypt swap pages and everything)&lt;/p&gt;


	&lt;p&gt;5. At this point, you should reboot the machine (to make sure that the settings come up properly on reboot) and test it between a workstation and the switch to make sure that the bridging is in fact working as advertised (outgoing interface now goes to the switch and the bridged interface goes to the workstation). Once you are certain that it is functioning properly, the additional internet connection can be added.&lt;/p&gt;


	&lt;h4&gt;Phase Two &amp;#8211; Adding another internet connection&lt;/h4&gt;


	&lt;p&gt;To add another connection, we basically repeat some of the steps above but for the new interface (in our case a &lt;span class="caps"&gt;DSL&lt;/span&gt; modem and em0)&lt;/p&gt;


	&lt;p&gt;1. Set the interface in /etc/rc.conf&lt;/p&gt;


&lt;pre&gt;echo "inet 192.168.1.64 255.255.0.0 NONE" &amp;gt; /etc/hostname.em0&lt;/pre&gt;

	&lt;p&gt;(You will need to alter this line depending on what type of configuration comes from your extra connection. In our case it&amp;#8217;s a broken Speedstream modem that can&amp;#8217;t really issue &lt;span class="caps"&gt;DHCP&lt;/span&gt; so we pick would would&amp;#8217;ve been discovered as a &lt;span class="caps"&gt;DHCP&lt;/span&gt; address as a static address.)&lt;/p&gt;


	&lt;p&gt;2. Reboot and try to ping the new device by IP. If you can&amp;#8217;t, don&amp;#8217;t bother moving on until you can otherwise you will simply destroy your network.&lt;/p&gt;


	&lt;h4&gt;Phase Three &amp;#8211; Configuring PF to &lt;span class="caps"&gt;NAT&lt;/span&gt; sometimes&lt;/h4&gt;


	&lt;p&gt;This step can be a little tricky because not all protocols can really be sliced out this way. &lt;span class="caps"&gt;FTP&lt;/span&gt; is a great example of this type of annoyance, but many other common ones such as &lt;span class="caps"&gt;SSH&lt;/span&gt;, HTTP, &lt;span class="caps"&gt;SMTP&lt;/span&gt;, IMAP have no issues at all. For the sake of clarity, I will just copy an entire example &lt;code&gt;pf.conf&lt;/code&gt; and explain it after the fact.&lt;/p&gt;


&lt;pre&gt;
#### Configuration for basic functions
# Specify our interfaces
ext_if1="fxp0" 
ext_if2="em0" 
ext_gw2="192.168.0.1" 
int_if="em1" 

# This contains localnet traffic that does not go out a T (shouldn't be state tracked (for this application anyway))
table &amp;lt;localnet&amp;gt; persist { 216.28.123.0/24 216.28.124.0/24 216.28.125.0/24 216.29.126.0/24 }

# Make this a # sign to disable the dsl routing
dsl_enable = "#" 

# A list of all ports to send through the dsl connection
dslports="{ 22 80 110 143 443 }" 
# Table of ips to use the dsl modem for outgoing traffic
dslnet = "{ 216.28.123.34/32 216.28.123.175/32 216.28.123.176/32 216.28.123.99/32 216.28.123.10/32 }" 

# Network address translations
$dsl_enable nat on $ext_if2 from $dslnet to any port $dslports -&amp;gt; ($ext_if2)

# Pass quick all of our local traffic without further ado
pass quick on { $ext_if1 $int_if } from &amp;lt;localnet&amp;gt; to &amp;lt;localnet&amp;gt;

# Run our load-balancer here
# pass our dsl ports first
$dsl_enable pass in quick on $int_if route-to ($ext_if2 $ext_gw2) proto { tcp udp } from $dslnet to !&amp;lt;localnet&amp;gt;  port $dslports modulate state label "DSL-1 $srcaddr:$dstport" 
$dsl_enable pass out quick on $ext_if1 route-to ($ext_if2 $ext_gw2) proto { tcp udp } from $ext_if2 to any port $dslports modulate state label "DSL-2 $srcaddr:$dstport" 

# Modulate state on all connections
pass on $ext_if1 modulate state
&lt;/pre&gt;

	&lt;p&gt;You can of course add filtering and optimizing rules here but for the purposes of this article, we&amp;#8217;ll stick to the salient points.&lt;/p&gt;


	&lt;p&gt;1. The definitions at the top define which interfaces and IPs go where. 192.168.0.1 is the IP address of our &lt;span class="caps"&gt;DSL&lt;/span&gt; gateway, you should use whatever the equivalent is.&lt;/p&gt;


	&lt;p&gt;2. The &lt;code&gt;&amp;lt;localnet&amp;gt;&lt;/code&gt; table helps to make sure that local traffic that normally bounces off of the router doesn&amp;#8217;t go out the &lt;span class="caps"&gt;DSL&lt;/span&gt; modem (and is right handy for queueing).&lt;/p&gt;


	&lt;p&gt;3. The $dsl_enable macro just lets is quickly and efficiently disable the &lt;span class="caps"&gt;DSL&lt;/span&gt; routing if there is a suspected problem.&lt;/p&gt;


	&lt;p&gt;4. The $dsl_ports macro lets us specify explicitly which outgoing connections should go through the &lt;span class="caps"&gt;DSL&lt;/span&gt; modem by destination port. Specifying which ones &lt;strong&gt;not&lt;/strong&gt; to go through will only frustrate you (yes, that is the voice of experience).&lt;/p&gt;


	&lt;p&gt;5. The $dsl_net macro lets us specify which internal machines are supposed to go through the &lt;span class="caps"&gt;DSL&lt;/span&gt;. Might be one of them, might be all of them, it&amp;#8217;s up to you.&lt;/p&gt;


	&lt;p&gt;6. The &lt;span class="caps"&gt;NAT&lt;/span&gt; line mangles the packets so they get routed/returned properly.&lt;/p&gt;


	&lt;p&gt;7. Pass all of the local traffic without mangling of any sort.&lt;/p&gt;


	&lt;p&gt;8. Route the &lt;span class="caps"&gt;DSL&lt;/span&gt; traffic appropriately. These are somewhat dense rules but I&amp;#8217;ll attempt to convert them to english:&lt;/p&gt;


	&lt;ul&gt;
	&lt;li&gt;Pass in any traffic coming into the internally bridged interface and route it to the &lt;span class="caps"&gt;DSL&lt;/span&gt; modem (udp and tcp only) from machines that are in the DSLnet that are making non-local connections on the dsl_ports.&lt;/li&gt;
		&lt;li&gt;Pass out traffic on the original external interface and route it to the &lt;span class="caps"&gt;DSL&lt;/span&gt; modem if it&amp;#8217;s from a machine in the DSLnet to a non-local dsl_port.&lt;/li&gt;
	&lt;/ul&gt;


	&lt;p&gt;9. Modulate state just for fun. Never hurts to have a clean &lt;span class="caps"&gt;TCP&lt;/span&gt; stream.&lt;/p&gt;


	&lt;p&gt;As an addendum, you&amp;#8217;ll notice that there are labels on the two lines that pass &lt;span class="caps"&gt;DSL&lt;/span&gt; traffic .. this is so that you can run &lt;code&gt;pfctl -vvsl&lt;/code&gt; and see whether or not and by how much it&amp;#8217;s working. For more information on what all those numbers mean, read the &lt;a href="http://www.openbsd.org/cgi-bin/man.cgi?query=pf.conf&amp;#38;apropos=0&amp;#38;sektion=0&amp;#38;manpath=OpenBSD+3.9&amp;#38;arch=i386&amp;#38;format=html"&gt;pf.conf&lt;/a&gt; man page.&lt;/p&gt;


	&lt;p&gt;Now it is time to enable pf:&lt;/p&gt;


&lt;pre&gt;
# pfctl -e
pf enabled
#
&lt;/pre&gt;

	&lt;p&gt;For it to be enabled on startup, edit the appropriate line in &lt;code&gt;/etc/rc.conf&lt;/code&gt;.&lt;/p&gt;


&lt;pre&gt;
pf=YES                  # Packet filter / NAT
&lt;/pre&gt;

	&lt;p&gt;Load in the ruleset:&lt;/p&gt;


&lt;pre&gt;
# pfctl -f /etc/pf.conf
#
&lt;/pre&gt;

	&lt;p&gt;At this point, if there are any errors in &lt;code&gt;pf.conf&lt;/code&gt;, the &lt;code&gt;pfctl&lt;/code&gt; should let you know where.&lt;/p&gt;


	&lt;p&gt;As an example, a line from &lt;code&gt;pfctl -vvsl&lt;/code&gt; on my setup now looks like:&lt;/p&gt;


&lt;pre&gt;DSL-1 216.28.123.99:80 17 702 377264&lt;/pre&gt;

	&lt;p&gt;Which means that the ip &lt;code&gt;216.28.123.99&lt;/code&gt; has sent transferred 702 packets for a total of 377264 bytes. Now, that doesn&amp;#8217;t mean much now, but after that snapshot I installed &lt;a href="http://www.freebsd.org"&gt;FreeBSD&lt;/a&gt; and used portsnap to download 41M at an average of 467K/s. For those of you who&amp;#8217;ve saturated a T1 line, you know that&amp;#8217;s about 2.5 times as fast as a T1. Yep, I&amp;#8217;d say it&amp;#8217;s working ;)&lt;/p&gt;


	&lt;h2&gt;Conclusion&lt;/h2&gt;


	&lt;p&gt;Having run this in a production environment for a small shop for a year and a half, it&amp;#8217;s certainly stable and reliable even though it likely breaks more RFCs than you can shake a stick at.  That said, let&amp;#8217;s sum up what this gives us:&lt;/p&gt;


	&lt;ul&gt;
	&lt;li&gt;Lots of extra bandwidth with &lt;strong&gt;zero&lt;/strong&gt; configuration other than swapping some cables and tweaking the bridge machine itself. This makes it &lt;strong&gt;really&lt;/strong&gt; nice to put into a legacy network where making alterations to the router or replacing it entirely are out of the question.&lt;/li&gt;
	&lt;/ul&gt;


	&lt;ul&gt;
	&lt;li&gt;Though fodder for another article, you can have more than one external connection and you can round-robin between them. You want 6Mbps*2? Get two &lt;span class="caps"&gt;DSL&lt;/span&gt; accounts. Or two cable modems. Or ten. You are really only limited here by the number of NICs you can force into the machine.&lt;/li&gt;
	&lt;/ul&gt;


	&lt;ul&gt;
	&lt;li&gt;If you are running servers on your network, this will not disrupt any of those connections since they are coming from external sources.&lt;/li&gt;
	&lt;/ul&gt;


	&lt;ul&gt;
	&lt;li&gt;Having an OpenBSD bridge in the network is a good thing anyway because you can queue traffic, &lt;a href="http://blog.insidesystems.net/articles/2006/06/06/OS-Fingerprinting-Email"&gt;passively OS fingerprint&lt;/a&gt;, log/graph, run intrusion detection, whatever you want to do (and yes, you can run two failover bridges if you are paranoid that this crazy blackbox might eat your whole network if it goes down, but that&amp;#8217;s another article)&lt;/li&gt;
	&lt;/ul&gt;


	&lt;p&gt;Also, if this saves you lots of money and time and effort, consider &lt;a href="http://www.openbsd.org/donations.html"&gt;donating some of it back to OpenBSD&lt;/a&gt;, they&amp;#8217;ve earned it.&lt;/p&gt;</description>
      <pubDate>Fri, 16 Jun 2006 15:15:00 -0400</pubDate>
      <guid isPermaLink="false">urn:uuid:fac2e6c5086b4db0dddd1a0099b3bda1</guid>
      <author>Kelley Reynolds</author>
      <link>http://blog.insidesystems.net/articles/2006/06/16/Stupid-Bridge-Tricks-1-How-to-add-more-bandwidth</link>
      <category>Networking</category>
      <category>OpenBSD</category>
      <category>System Administration</category>
      <trackback:ping>http://blog.insidesystems.net/articles/trackback/3</trackback:ping>
    </item>
    <item>
      <title>"Stupid Bridge Tricks #1 - How to add more bandwidth" by Kelley Reynolds</title>
      <description>&lt;p&gt;To be honest with you, it might not &lt;strong&gt;actually&lt;/strong&gt; break any RFCs but it really seems like it ought to. Mostly it&amp;#8217;s just to let people know it&amp;#8217;s a dirty hack and to be aware of that fact if they decide to put it into production (though it appears to be a reliable dirty hack given the years we&amp;#8217;ve used it in production with no ill effect).&lt;/p&gt;


	&lt;p&gt;For an increasing number of situations we deal with, it&amp;#8217;s a great solution to instantly increase bandwidth without any sort of more complicated rejiggering&amp;#8230; very handy for clients who have outgrown  capacity on one line but (decide not to|can&amp;#8217;t) afford a complete network restructuring.&lt;/p&gt;</description>
      <pubDate>Mon, 19 Jun 2006 01:15:31 -0400</pubDate>
      <guid isPermaLink="false">urn:uuid:</guid>
      <link>http://blog.insidesystems.net/articles/2006/06/16/Stupid-Bridge-Tricks-1-How-to-add-more-bandwidth#comment-13</link>
    </item>
    <item>
      <title>"Stupid Bridge Tricks #1 - How to add more bandwidth" by frank</title>
      <description>&lt;p&gt;&amp;gt; even though it likely breaks more RFCs than you can shake a stick at&lt;/p&gt;


	&lt;p&gt;I&amp;#8217;m just curious (and maybe stupid): which ones?&lt;/p&gt;


	&lt;p&gt;btw: great article giving a &amp;#8220;ready rolled&amp;#8221; experience :-)&lt;/p&gt;</description>
      <pubDate>Sun, 18 Jun 2006 00:17:20 -0400</pubDate>
      <guid isPermaLink="false">urn:uuid:</guid>
      <link>http://blog.insidesystems.net/articles/2006/06/16/Stupid-Bridge-Tricks-1-How-to-add-more-bandwidth#comment-15</link>
    </item>
  </channel>
</rss>
