<?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>geek scrap &#187; multihoming</title>
	<atom:link href="http://geekscrap.com/tags/multihoming/feed/" rel="self" type="application/rss+xml" />
	<link>http://geekscrap.com</link>
	<description>there is at least one way to do it</description>
	<lastBuildDate>Tue, 12 Apr 2011 10:14:14 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	
		<item>
		<title>Multiple IP uplinks with Gentoo</title>
		<link>http://geekscrap.com/2010/02/multiple-ip-uplinks-with-gentoo/</link>
		<comments>http://geekscrap.com/2010/02/multiple-ip-uplinks-with-gentoo/#comments</comments>
		<pubDate>Wed, 17 Feb 2010 08:00:32 +0000</pubDate>
		<dc:creator>geekscrap</dc:creator>
				<category><![CDATA[How-tos]]></category>
		<category><![CDATA[Sysadmin]]></category>
		<category><![CDATA[gentoo]]></category>
		<category><![CDATA[iproute2]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[multihoming]]></category>
		<category><![CDATA[policy routing]]></category>
		<category><![CDATA[split access]]></category>
		<category><![CDATA[vlan]]></category>

		<guid isPermaLink="false">http://geekscrap.com/?p=739</guid>
		<description><![CDATA[When your computer or server has access to multiple LAN segments with different address spaces and different gateways to the Internet, there&#8217;s a nice feature called policy routing that allows you to use all of them simultaneously without having to re-configure your network topology. This is especially useful when you want to increase the bandwidth and [...]]]></description>
			<content:encoded><![CDATA[<p>When your computer or server has access to multiple LAN segments with different address spaces and different gateways to the Internet, there&#8217;s a nice feature called <em>policy routing</em> that allows you to use all of them simultaneously without having to re-configure your network topology. This is especially useful when you want to increase the bandwidth and resilience of a single computer or server without the burden of being an Autonomous System (BGP peering, Internet Registry bureaucracy, etc.).</p>
<p>Here are the steps to setup multiple uplinks through policy routing on Gentoo:</p>
<p><span id="more-739"></span></p>
<ol>
<li>First of all, to access multiple networks, either you have multiple physical NICs or you need to configure your network uplink to let your network ports access multiple VLANs. For more information on VLANs configurations under Gentoo, you can check Gentoo Handbook <a rel="nofollow" href="http://www.gentoo.org/doc/en/handbook/handbook-x86.xml?part=4&amp;chap=3#doc_chap10">section on VLANs</a>.</li>
<li>On Linux kernel, you need to enable CONFIG_IP_MULTIPLE_TABLES option (in Linux kernel menuconfig, you find it under <em>Networking support =&gt; Networking options =&gt; IP: policy routing</em>). <a rel="nofollow" href="http://www.gentoo.org/doc/en/handbook/handbook-x86.xml?part=1&amp;chap=7">Recompile and install kernel</a>.</li>
<li>Next, you need to install iproute2 package, which allows editing multiple routing tables:
<pre># emerge -av sys-apps/iproute2</pre>
</li>
<li>Edit <em>/etc/iproute2/rt_tables</em> and add the following route table lines:
<pre>100        T0
101        T1</pre>
</li>
<li>Edit your <em>/etc/conf.d/net</em> file to enable network startup configuration. First add the following lines, modifying addresses and interface names to suit your needs:
<pre lang="bash">config_eth0=( "192.168.0.100/24" )
routes_eth0=(
    "192.168.0.0/24 src 192.168.0.100 table T0"
    "default via 192.168.0.1 table T0"
    "default nexthop via 192.168.0.1 weight 1"
)
rules_eth1=("from 192.168.1.1/32 table T0 priority 100" )

config_eth1=( "192.168.1.200/24" )
routes_eth0=(
    "192.168.1.0/24 src 192.168.1.200 table T1"
    "default via 192.168.1.1 table T1"
    "default nexthop via 192.168.0.1 weight 1"
)
rules_eth1=("from 192.168.1.100/32 table T1 priority 101" )</pre>
<p>Then uncomment the following functions (if you copied your /etc/conf.d/net from /etc/conf.d/net.example, they should be already there in comments):</p>
<pre lang="bash">postup() {
       local x="rules_${IFVAR}[@]"
       local -a rules=( "${!x}" )
       if [[ -n ${rules} ]] ; then
               einfo "Adding IP policy routing rules"
               eindent
               # Ensure that the kernel supports policy routing
               if ! ip rule list | grep -q "^" ; then
                       eerror "You need to enable IP Policy Routing (CONFIG_IP_MULTIPLE_TABLES)"
                       eerror "in your kernel to use ip rules"
               else
                       for x in "${rules[@]}" ; do
                               ebegin "${x}"
                               ip rule add ${x} dev "${IFACE}"
                               eend $?
                       done
               fi
               eoutdent
               # Flush the cache
               ip route flush cache dev "${IFACE}"
       fi
}

postdown() {
       # Automatically erase any ip rules created in the example postup above
       if interface_exists "${IFACE}" ; then
               # Remove any rules for this interface
               local rule
               ip rule list | grep " iif ${IFACE}[ ]*" | {
                       while read rule ; do
                               rule="${rule#*:}"
                               ip rule del ${rule}
                       done
               }
               # Flush the route cache
               ip route flush cache dev "${IFACE}"
       fi

       # Return 0 always
       return 0
}</pre>
</li>
<li>Finally, reboot with your new kernel. My advice is to proceed with this step while you can access your machine locally, just in case anything goes wrong.</li>
</ol>
<p>Some in-depth on what I described above: with policy routing you can insert additional routing tables and configure your system to use a set of rules to decide which table to apply for each IP packet. So if you create T0 and T1 tables, you can set your host to respond to requests from each interface back to the same interface and load balance routes going to outer network by giving the same <em>weight</em> to both gateways in generic route table.</p>
<p>If you use this setup to publish your server on multiple public networks, you will probably need to configure multiple DNS A records in round-robin over your IPs.</p>
<p>If you&#8217;re interested in more Gentoo tips, just <a href="http://geekscrap.com/feed/">subscribe</a> to my feed or <a rel="nofollow" href="http://twitter.com/geekscrap">follow me</a> on Twitter.</p>
]]></content:encoded>
			<wfw:commentRss>http://geekscrap.com/2010/02/multiple-ip-uplinks-with-gentoo/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
<!-- WP Super Cache is installed but broken. The path to wp-cache-phase1.php in wp-content/advanced-cache.php must be fixed! -->
