Search:  
Gentoo Wiki

TIP_Dual-Homed_Gentoo_Server

This article is part of the Tips & Tricks series.
Terminals / Shells Network X Window System Portage System Filesystems Kernel Other

Contents

Situation

For one reason or another, you have internet connections from 2 different providers, or 2 connections from a single provider but with different gateways, coming in to a single machine. An example would be when you have a primary IP which is part of a trusted network range for NFS, etc. without an internal LAN, but would like to run a secondary DNS server on a separate IP range.

Kernel Support

You need to have a couple of kernel options enabled:

These enable filtering based on the source address, as opposed to being restricted to only the destination address (default).

Verify they are enabled in your kernel:

$ grep -e CONFIG_IP_ADVANCED_ROUTER -e CONFIG_IP_MULTIPLE_TABLES /usr/src/linux/.config 
  CONFIG_IP_ADVANCED_ROUTER=y
  CONFIG_IP_MULTIPLE_TABLES=y

To enable the above 2 items in the kernel, run make menuconfig in the /usr/src/linux directory. Navigate to Networking --> Networking options and change "IP: Advanced router" and "IP: policy routing" to [*]. Save your changes and run make && make modules_install. Double check the items are enabled by running the grep command above again.

Software Support

You will need to emerge iproute2. ifconfig cannot handle multiple routing tables, nor can it handle a number of other things that iproute2 can, so using iproute2 instead is a good idea anyway.

Configuration

100     dns
ip rule add from <secondary ip> table dns
modules=( "iproute2" )
config_eth0=(
        "<primary ip>/<nm> brd <primary broadcast>"
)
config_eth1=(
        "<secondary ip>/<nm> brd <secondary broadcast>"
)
routes_eth0=(
        "default via <primary gateway>"
)
routes_eth1=(
        "127.0.0.0/8 dev lo table dns"
        "default via <secondary gateway> table dns"
)

For example "<primary ip>/<nm> brd <primary broadcast>" should look like :

123.124.125.3/24 brd 123.124.125.255

Notes

modules=( "iproute2" )
config_eth0=(
        "<primary ip>/<nm> broadcast <primary broadcast>"
        "<secondary ip>/<nm> broadcast <secondary broadcast>"
)
routes_eth0=(
        "default via <primary gateway>"
        "127.0.0.0/8 dev lo table dns"
        "default via <secondary gateway> table dns"
)
routes_eth3=(
        "10.0.0.0/8 table mx"
)

Credit and Links

This article was originally written by Casey Allen Shobe for SeattleServer.com, based on information from the Linux Advanced Routing and Traffic Control HOWTO, simplified and tailored to Gentoo.

Retrieved from "http://www.gentoo-wiki.info/TIP_Dual-Homed_Gentoo_Server"

Last modified: Sun, 08 Jun 2008 06:02:00 +0000 Hits: 15,885