4

I want to route packets coming in on eth0 back over eth0 and the ones coming in to eth1 back over eth1. I don't care which gateway is used for outgoing connections.

If i just enter two gateways in /etc/network/interfaces then the kernel routes packets out on both interfaces.

I remember it has something to do with routing tables but I don't know how to do it/where can I read more about it.

Kara Marfia
  • 7,892
  • 5
  • 32
  • 56
Jure1873
  • 3,692
  • 1
  • 21
  • 28

3 Answers3

3

What you want to achieve is multi-homing, not bonding or load-balancing.

To do this you'll need to implement what is known as "policy" or "source based" routing.

Which you can do in Linux by using the iproute2 package.

There is a good article that explains how to, here.

Dan Carley
  • 25,189
  • 5
  • 52
  • 70
  • This just solved about 3 hrs of banging my head against a brick wall. "Why arn't packets coming back...... disable rp_filter" Thanks a bunch! :) – Jason Mar 01 '10 at 23:38
  • This is probably what I'm looking for in http://serverfault.com/questions/567487/iptables-packet-forwarding-to-one-of-two-gateways-depending-on-origin/567515. Unfortunately, the link is broken :-( – Daniel Alder Jan 17 '14 at 23:03
0

I have implemented a working MultiISP setup using shorewall based on this answer: NIC bonding with two uplinks

It easy to implement and manage, works well in a "load balancing" configuration, where packets are evenly distributed between uplinks if no cached routes are found.

Read more about it here: http://www.shorewall.net/MultiISP.html

Karolis T.
  • 2,709
  • 7
  • 32
  • 45
  • 1
    Ok, thanks I don't need load balancing but it should work so I'll try that. – Jure1873 Jul 23 '09 at 08:52
  • No problem. Although raw iproute2 solutions are ok, having shorewall gives you a very nice abstraction and less maintenance problems for acomplishing the same task. – Karolis T. Jul 23 '09 at 13:10
0

I found this web page describing exactly how to achieve this using iptables2.

I found it using google and "linux 2 default gateways"

chris
  • 11,784
  • 6
  • 41
  • 51