Example 8-8 demonstrates the use of different metrics (the least preferable is referred to as a floating static route) for the same prefix as well as equal metrics for load balancing. The BSD world only supplies metrics in context with interfaces (see Example 8-9). This is not a deficiency, but is instead a design choice to leave these issues to dynamic routing protocols.
If you use two routes with an equal metric value, load balancing is done on a per-connection basis; if you specify the Linux equalize keyword on two routes, load balancing is done on a per-packet basis. In this case, the route is just recomputed for every packet. Without it, the route stays cached and bound to a specific next hop as long as it is up and alive.
Example 8-8 starts with adding two unequal-cost routes to the same destination prefix via the route and different prefixes via the ip route command sequence to demonstrate a floating static route setup. This is different on a Cisco router: The floating static route is added only to the routing table "on demand," when the preferable prefix route fails, hence the name floating. The second command sequence of Example 8-8 establishes a mix of per-destination and per-packet (equalize) load-balanced ECMP. As you can see from the following output in Example 8-9, both unequal metric routes are placed in the routing table. The ECMP routes have the same weight, 1, and the two per-packet load-balanced ECMP routes are labeled with the equalize flag (shaded text).
[root@callisto:~#] route add ?net 11.1.1.0/24 metric 2 gw 192.168.1.254 [root@callisto:~#] route add ?net 11.1.1.0/24 metric 1 gw 192.168.14.254 [root@callisto:~#] ip route add 11.1.2.0/24 via 192.168.1.254 metric 2 [root@callisto:~#] ip route add 11.1.2.0/24 via 192.168.14.254 metric 1 [root@callisto:~#] ip route add 10.1.1.0/24 equalize nexthop via 192.168.1.254 dev eth1 nexthop via 192.168.14.254 dev eth0 [root@callisto:~#] ip route add 10.1.5.0/24 nexthop via 192.168.1.254 nexthop via 192.168.14.254
[root@callisto:~#] ip route help Usage: ip route { list | flush } SELECTOR ip route get ADDRESS [ from ADDRESS iif STRING ] [ oif STRING ] [ tos TOS ] ip route { add | del | change | append | replace | monitor } ROUTE SELECTOR := [ root PREFIX ] [ match PREFIX ] [ exact PREFIX ] [ table TABLE_ID ] [ proto RTPROTO ] [ type TYPE ] [ scope SCOPE ] ROUTE := NODE_SPEC [ INFO_SPEC ] NODE_SPEC := [ TYPE ] PREFIX [ tos TOS ] [ table TABLE_ID ] [ proto RTPROTO ] [ scope SCOPE ] [ metric METRIC ] INFO_SPEC := NH OPTIONS FLAGS [ nexthop NH ]... NH := [ via ADDRESS ] [ dev STRING ] [ weight NUMBER ] NHFLAGS OPTIONS := FLAGS [ mtu NUMBER ] [ advmss NUMBER ] [ rtt NUMBER ] [ rttvar NUMBER ] [ window NUMBER] [ cwnd NUMBER ] [ ssthresh REALM ] [ realms REALM ] TYPE := [ unicast | local | broadcast | multicast | throw | unreachable | prohibit | blackhole | nat ] TABLE_ID := [ local | main | default | all | NUMBER ] SCOPE := [ host | link | global | NUMBER ] FLAGS := [ equalize ] NHFLAGS := [ onlink | pervasive ] RTPROTO := [ kernel | boot | static | NUMBER ] [root@callisto:~#] ip route show 192.168.1.0/24 dev eth1 scope link 192.168.1.0/24 dev ipsec0 proto kernel scope link src 192.168.1.1 10.1.5.0/24 nexthop via 192.168.1.254 dev eth1 weight 1 nexthop via 192.168.14.254 dev eth0 weight 1 192.168.14.0/24 dev eth0 scope link 11.1.2.0/24 via 192.168.14.254 dev eth0 metric 1 11.1.2.0/24 via 192.168.1.254 dev eth1 metric 2 10.1.1.0/24 equalize nexthop via 192.168.1.254 dev eth1 weight 1 nexthop via 192.168.14.254 dev eth0 weight 1 11.1.1.0/24 via 192.168.14.254 dev eth0 metric 1 11.1.1.0/24 via 192.168.1.254 dev eth1 metric 2 127.0.0.0/8 dev lo scope link default via 192.168.1.254 dev eth1 [root@callisto:~#] route -n Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 192.168.1.0 0.0.0.0 255.255.255.0 U 0 0 0 eth1 192.168.1.0 0.0.0.0 255.255.255.0 U 0 0 0 ipsec0 10.1.5.0 192.168.1.254 255.255.255.0 UG 0 0 0 eth1 192.168.14.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0 11.1.2.0 192.168.14.254 255.255.255.0 UG 1 0 0 eth0 11.1.2.0 192.168.1.254 255.255.255.0 UG 2 0 0 eth1 10.1.1.0 192.168.1.254 255.255.255.0 UG 0 0 0 eth1 11.1.1.0 192.168.14.254 255.255.255.0 UG 1 0 0 eth0 11.1.1.0 192.168.1.254 255.255.255.0 UG 2 0 0 eth1 127.0.0.0 0.0.0.0 255.0.0.0 U 0 0 0 lo 0.0.0.0 192.168.1.254 0.0.0.0 UG 0 0 0 eth1
As previously mentioned, BSD Unices do not provide metrics in context with the route command. However, you can assign metrics to interfaces, as demonstrated in Example 8-10 (shaded text).
[root@ganymed:~#] ifconfig ne4 metric 5 [root@ganymed:~#] ifconfig -A ... ne4: flags=8863<UP,BROADCAST,NOTRAILERS,RUNNING,SIMPLEX,MULTICAST> metric 5 mtu 1500 media: Ethernet 10baseT full-duplex inet 192.168.2.254 netmask 0xffffff00 broadcast 192.168.2.255 inet6 fe80::5054:5ff:fee3:e42f%ne4 prefixlen 64 scopeid 0x2 ...