You are not logged in.

#1 2009-02-10 07:05:35

MindlessXD
Member
Registered: 2007-11-08
Posts: 18

routing outgoing packets over multiple interfaces?

I have two network interfaces (eth0 and eth1) with separate IP addresses on the same subnet.  All outgoing traffic uses eth0 regardless of the interface the incoming traffic came in on.
I assume the outgoing packets still have the correct source IP address (not always eth0's), and I'd like the packets to go out on the interface with the corresponding IP address.

I think I have half the solution to my problem:
http://www.novell.com/support/viewConte … Id=7000318

The other half is that my IPs are dynamic, so ddclient could change my IPs and then the routing would be invalid.

Last edited by MindlessXD (2009-02-10 07:06:16)

Offline

#2 2009-02-12 15:10:38

wsduvall
Member
From: Blacksburg
Registered: 2009-02-05
Posts: 54
Website

Re: routing outgoing packets over multiple interfaces?

You might want to talk a look at this: http://wiki.archlinux.org/index.php/NAT … connection. This is probably not what you want, but it may help.


My 5 node 9 CPU cluster: www.amenrecluster.com
OS: Arch Linux
Machines:Fujitsu T4210 and IBM eServer xSeries 335

Offline

#3 2009-02-12 18:14:23

mcover
Member
From: Germany
Registered: 2007-01-25
Posts: 134

Re: routing outgoing packets over multiple interfaces?

A while back I wrote myself a script to setup a routing table for load-balancing between two interfaces (not what you want) but here are some bash-functions that I wrote that may help you getting the dynamic addresses:

#arg0 = ifdev
get_netmask ()
{
    ifconfig $1 | grep -m 1 'Mask' | awk '{print $4}' | awk -F":" '{print $2}'
}

#arg0 = ifdev
get_ip ()
{
    ifconfig $1 | grep -m 1 'inet addr' | awk '{print $2}' | awk -F":" '{print $2}'
}

#arg0 = ifdev
get_gateway ()
{
    route -n | grep $1 | sed "s/default/0.0.0.0/g" | sed "s/^.*:.*$//g" | grep "^0.0.0.0" | awk '{print $2}'
}

#arg0 = ifdev arg1 = ifdev's IP
get_cider_mask ()
{
    ip route | grep "$1.*src *$2" | awk '{print $1}'
}

From here you could go and write yourself a script.

m.

Last edited by mcover (2009-02-12 18:14:51)

Offline

#4 2009-02-12 19:22:26

ckristi
Member
From: Bucharest, Romania
Registered: 2006-11-21
Posts: 225

Re: routing outgoing packets over multiple interfaces?

I think this might be what you need:
http://wiki.archlinux.org/index.php/Con … rk#bonding


In love I believe and in Linux I trust

Offline

#5 2009-02-12 22:14:39

fukawi2
Ex-Administratorino
From: .vic.au
Registered: 2007-09-28
Posts: 6,222
Website

Re: routing outgoing packets over multiple interfaces?

Setup custom route tables to be used depending on the iptables conntrack marks below

ip route flush table 1
ip rule del fwmark 101 table 1
ip route add table 1 default via <ETH0 IP ADDRESS>
ip rule add fwmark 101 table 1
ip route flush table 2
ip rule del fwmark 102 table 2
ip route add table 2 default via <ETH1 IP ADDRESS>
ip rule add fwmark 102 table 2

I'm not 100% sure if you can add a route via the interfaces IP address. This code has been modified from a box using 2 different ISP's so they have different upstream routers. You might need to replace the 'via' parts with 'src'

# Ensure traffic in one interface goes back out the same interface
iptables -t mangle -F PREROUTING
iptables -t mangle -A PREROUTING -j CONNMARK --restore-mark
iptables -t mangle -A PREROUTING -m mark ! --mark 0 -j ACCEPT
iptables -t mangle -A PREROUTING -i eth0 -m state --state NEW -j MARK --set-mark 101
iptables -t mangle -A PREROUTING -i eth1 -m state --state NEW -j MARK --set-mark 102

Offline

Board footer

Powered by FluxBB