1
edit
Changes
no edit summary
Sometimes you have more than one router in your network, and want different [[container]]s to use different routers. For that, Other times you may have a single HN with IP addresses on different networks and want to assign containers addresses from those networks. Lets say you have a HN with an IP address in network 192.168.100.0/24 (192.168.100.10) and an IP address in 192.168.200.0 (192.168.200.10). Maybe those addresses are on different VLANs. Maybe one is an internal network and the other faces the wider internet. Maybe you have 10 different networks assigned to the HN. It does not matter as long as there is a gateway on each of those networks. In our example we will assume the gateways are 192.168.100.1 and 192.168.200.1. You want any container assigned an address in the 192.168.100.0/24 network to use 192.168.100.1 and any container assigned an address in the 192.168.200.0/24 network to use 192.168.200.1. By default the network traffic coming from a container will use the default gateway on the HN to reach the rest of the world. If we want our containers to use the gateways on their respective networks we need to set up configure source-based routing on . This involves creating an additional routing table to redirect the host systemtraffic. For example: <pre># /sbin/ip rule add from 192.168.100.0/24 table 10000# /sbin/ip route add throw 192.168.100.0/24 table 10000# /sbin/ip route add default via 192.168.100.1 table 10000</pre> The first line adds a routing rule. This rule tells the system to use an alternate routing table when trying to route packets from a certain source. In this case we are telling the system that if a packet originates from a 192.168.100.0/24 address we should use routing table 10000. The table number is unique and simply must be an unused table number from your system. I tend to start at 10000, but you can start your number wherever is convenient. To see a list of tables in use you can use:
<pre>
# /sbin/ip rule add from $IP table $TBL# /sbin/ip route add default dev eth0 via $GW table $TBLlist
</pre>
For more details on routing rules, see <code>man ip</code>.