Source based routing

From OpenVZ Virtuozzo Containers Wiki
Revision as of 17:41, 20 July 2006 by Kir (talk | contribs) (wikified, categorized, enlarged)
Jump to: navigation, search

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