Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

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 a Linux box running Ubuntu 10.04 with three interfaces: eth0, eth1 and eth2. I am planning to use it as a WAN router for 4 public subnets assigned by two different ISP's. Here are the subnets (I have converted the ISP assigned subnets to class C private subnets):

ISP 1   
WAN gateway   

ISP 2   
WAN gateway  

/30 subnets face respectives ISPs and /29 subnets face my LAN switch.

This is how IPs are assigned to the interfaces:

LAN interface 

ISP 1 interface

ISP 2 interface

I want to route traffic between respective ISP assigned /30 and /29 subnets separetly. If traffic comes from one ISP's /30 network, it should be routed to that ISPs /29 network and visa versa. I don't mind if traffic originated in one ISP's /29 network destined to the other ISP's /29 network gets routed in my router (without getting it sent to one ISP and comes back other ISP's link).

My aim is to not to buy two routers for two ISP's. How can I achieve this by using iproute2 tables and policy routing?

share|improve this question

First, create a routing table for each ISP (only done once):

echo "11 isp1" >> /etc/iproute2/rt_tables
echo "12 isp2" >> /etc/iproute2/rt_tables

Then add a default route to each table pointing to the corresponding gateway:

ip route add default via table isp1
ip route add default via table isp2

Then add rules to send traffic to these tables based on the source address:

ip rule add from table isp1
ip rule add from table isp1
ip rule add from table isp2
ip rule add from table isp2
share|improve this answer

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.