From wikistone
Jump to: navigation, search
 
Line 1: Line 1:
 
==Debian==
 
==Debian==
−
Assuming two interfaces (eth0 and eth1) on different subnets.
+
Assuming two interfaces (eth0 and eth1) on different subnets, we want to route traffic from those subnets through the correct interface and to the correct gateway. We also want to set the default interface and gateway used if source is not specified.
  
 
Add tables to /etc/iptables2/rt_tables :
 
Add tables to /etc/iptables2/rt_tables :
Line 18: Line 18:
 
Set default interface to use for traffic:
 
Set default interface to use for traffic:
 
<pre>
 
<pre>
−
post-up ip route change to default dev eth1 via 10.0.1.1
+
post-up ip route change to default dev eth1 via [eth1_gw]
 
</pre>
 
</pre>
  
Line 33: Line 33:
 
post-up ip route add default via 10.0.1.1 table exede
 
post-up ip route add default via 10.0.1.1 table exede
 
post-up ip rule add from 10.0.1.0/24 lookup exede
 
post-up ip rule add from 10.0.1.0/24 lookup exede
 +
post-up ip route change to default dev eth1 via 10.0.1.1
 
</pre>
 
</pre>

Latest revision as of 12:30, 20 April 2014

Debian

Assuming two interfaces (eth0 and eth1) on different subnets, we want to route traffic from those subnets through the correct interface and to the correct gateway. We also want to set the default interface and gateway used if source is not specified.

Add tables to /etc/iptables2/rt_tables :

# echo "table0" >> /etc/iptables2/rt_tables
# echo "table1" >> /etc/iptables2/rt_tables

Add rules to /etc/network/interfaces :

post-up ip route add default via [eth0_gw] table table0
post-up ip rule add from [eth0_network/cidr] lookup admin
post-up ip route add default via [eth1_gw] table table1
post-up ip rule add from [eth1_network/cidr] lookup exede

Set default interface to use for traffic:

post-up ip route change to default dev eth1 via [eth1_gw]

Example:

auto eth0   # network 10.0.0.0
iface eth0 inet dhcp

auto eth1   # network 10.0.1.0
iface eth1 inet dhcp

post-up ip route add default via 10.0.0.1 table admin
post-up ip rule add from 10.0.0.0/24 lookup admin
post-up ip route add default via 10.0.1.1 table exede
post-up ip rule add from 10.0.1.0/24 lookup exede
post-up ip route change to default dev eth1 via 10.0.1.1