Difference between revisions of "Source based routing"

From OpenVZ Virtuozzo Containers Wiki
Jump to: navigation, search
 
(wikified, categorized, enlarged)
Line 1: Line 1:
IP source based routing
+
Sometimes you have more than one router in your network, and want different [[VE]]s to use different routers. For that, you need to set up source-based routing on the host system. For example:
 
 
to setup src-based routing rules in host system. e.g.
 
  
 
<pre>
 
<pre>
Line 8: Line 6:
 
</pre>
 
</pre>
  
where $IP is ip address which should use non-default GW.
+
where  
$GW is gateway for this IP addr
+
* <code>$IP</code> is an IP address which should use non-default gateway. You can also use netmask here, e.g. <code>10.9.8.0/24</code> will mean that all VEs with addresses like 10.9.8.x will be routed through the given gateway.
$TBL - any free table number, I use numbers from 6 to ...
+
* <code>$GW</code> is a gateway for this IP address.
every next non-std GW will require another table number
+
* <code>$TBL</code> is any free table number, I use numbers from 6 upwards. Note that tables 250-255 are usually reserved (see <code>/etc/iproute2/rt_tables</code>.
 +
 
 +
Note that every new non-standard gateway will require another table number.
  
read `man ip` for routing rules details.
+
For more details on routing rules, see <code>man ip</code>.
  
http://forum.openvz.org/index.php?t=msg&goto=1631&&srch=src+routing#msg_1631
+
== See also ==
http://forum.openvz.org/index.php?t=tree&th=492&mid=2881&&rev=&reveal=
+
[http://forum.openvz.org/index.php?t=msg&th=268 Forum thread #268]
 +
[http://forum.openvz.org/index.php?t=msg&th=492 Forum thread #492]
  
Category:HOWTO
+
[[Category:Networking]]
 +
[[Category:HOWTO]]

Revision as of 17:41, 20 July 2006

Sometimes you have more than one router in your network, and want different VEs to use different routers. For that, you need to set up source-based routing on the host system. For example:

# /sbin/ip rule add from $IP table $TBL
# /sbin/ip route add default dev eth0 via $GW table $TBL

where

  • $IP is an IP address which should use non-default gateway. You can also use netmask here, e.g. 10.9.8.0/24 will mean that all VEs with addresses like 10.9.8.x will be routed through the given gateway.
  • $GW is a gateway for this IP address.
  • $TBL is any free table number, I use numbers from 6 upwards. Note that tables 250-255 are usually reserved (see /etc/iproute2/rt_tables.

Note that every new non-standard gateway will require another table number.

For more details on routing rules, see man ip.

See also

Forum thread #268 Forum thread #492