Saturday, February 6, 2010

Two Gateways on Ubuntu, Split access.

I set my Ubuntu server with to private gateways, which had access too two public ip addresses. I wanted to receive requests to the web tomcat and apache servers from both networks. This is how I configured my split access on my server to have traffic come in through both private subnets and sent out through the ip that it came in on.



#!/bin/sh

# split access
# http://lartc.org/howto/lartc.rpdb.multiple-links.html#AEN268
# http://tldp.org/HOWTO/Adv-Routing-HOWTO/lartc.rpdb.multiple-links.html
# GoneVertical.org

# 1. One creates two additional routing tables, say T1 and T2. These are added in /etc/iproute2/rt_tables. Then you set up routing in these tables as follows:
# echo 1 T1 >> /etc/iproute2/rt_tables
# echo 2 T2 >> /etc/iproute2/rt_tables

# interface
IF0=lo
IF1=eth0
IF2=eth1

# ips
IP1=192.168.12.100
IP2=192.168.10.100

# gateways
P1=192.168.12.1
P2=192.168.10.1

# ip network
P0_NET=0.0.0.0
P1_NET=192.168.12.0
P2_NET=192.168.10.0

#echo $IF0 $IF1 $IF2
#echo $IP1 $IP2
#echo $P0_NET $P1_NET $P2_NET

# create routing tables
ip route add $P1_NET dev $IF1 src $IP1 table T1
ip route add default via $P1 table T1
ip route add $P2_NET dev $IF2 src $IP2 table T2
ip route add default via $P2 table T2

# create routing for local requests
# not sure if i need this
#ip route add $P0_NET dev $IF0 table T1
#ip route add $P2_NET dev $IF2 table T1
#ip route add 127.0.0.0/8 dev lo table T1
#ip route add $P0_NET dev $IF0 table T2
#ip route add $P1_NET dev $IF1 table T2
#ip route add 127.0.0.0/8 dev lo table T2


# main routing table
ip route add $P1_NET dev $IF1 src $IP1
ip route add $P2_NET dev $IF2 src $IP2

# default route preference
ip route add default via $P1

# routing rules
ip rule add from $IP1 table T1
ip rule add from $IP2 table T2

1 comment:

alex gargour said...

Thank you, just what I needed, works great, just needed to add localhost route so that the machine itself could reach outside

Trying out the Dart Analysis Server

I wanted to see how the Dart Analysis Server was put together and worked. I started looking to see how I could wire it up and try out the co...