Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have two ADSL modem-routers and a server all in the same statically-assigned IP address range (

Internet 1 -- ( Modem 1 ( -- Switch -- ( Server 
Internet 2 -- ( Modem 2 ( -----/

Each of the modems forward ports to the server, e.g. ssh. This works on one modem but not the other. If I do a packet trace, the ssh packets arrive at the server and are returned via the default gateway, which may have a different external IP to the origin. If it does not match the origin, the response is thrown away and the ssh connection times out.

e.g. If the default gateway in the server is, then the ssh packets would take the following paths:

Request:  SSH to -> ->
Response: -> ->
Result: WORKS! :-D

Request:  SSH to -> ->
Response: -> ->

I understand from chatting with the people on IRC ##networking that what I want is "Source-Based Routing", a type of Policy Based Routing.

From what I can tell, a PBR looks something like:

access-list 1 permit
access-list 2 permit
interface async 1
 ip policy route-map equal-access
route-map equal-access permit 10
 match ip address 1
 set ip default next-hop
route-map equal-access permit 20
 match ip address 2
 set ip default next-hop
route-map equal-access permit 30
 set default interface null0

I have spent many hours looking at tutorials and examples on this, but they don't seem to come near my needs. Specifically, I can't seem to understand:

  1. How the originating IP is matched to the response IP,
  2. The meaning of 'async' in the above example,
  3. If the above example is even remotely correct for my needs, and
  4. Where I should put this configuration on a standard Ubuntu Server?
share|improve this question
up vote 2 down vote accepted

You need to add an additional IP to the server (eg and DNAT the traffic coming to ADSL Modem 2 to the new address. This way the server will be able to differentiate between the 2 upstream connections; at the moment it can't do that because all traffic that it sees is destined to from whatever source address out on the internet with no indication of which ADSL modem the packet traversed.

With the additional IP setup, in your Policy Based Routing, you connection mark any traffic to with a mark that uses a route table that default routes to ADSL Modem 1, and connection mark traffic to with a mark to use a routing table with ADSL Modem 2 as the default gateway.

share|improve this answer
This makes some sense. I'm confused by your reference to PBR, tho. If I add an extra IP and then simply do "route add gw", does PBR become unnecessary? – tudor May 14 '13 at 5:48
@tudor No, that's a complete misunderstanding of how route tables work. You need the PBR to ensure correct selection of the next-hop router ( and that has nothing to do with the destination address of the original (inbound) packet, unless you connection mark it when it arrives so the return packet is associated with it so the correct route table is used. I wrote a script that does this kind of thing that might help get you on your way with a starting point if nothing else; search GitHub for 'pb-route' – fukawi2 May 14 '13 at 23:30

I've set this up in the past using policy routing from the Linux Advanced Routing and Traffic Control Howto.

In your case, you appear to have a slightly different configuration with a switch in the middle. You can adapt your configuration to the suggestion perhaps by adding a second nic. Otherwise, you may need to setup multiple VLANs to accomplish what you are after with a single nic.

share|improve this answer
Unfortunately, if I follow these instructions, then that means that "Linux Router" (as opposed to a simple switch) becomes a single point of failure. So yes, my configuration and requirements are different. – tudor May 14 '13 at 5:53

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.