Linux kernel decision making process for routing table

linuxredhatrouting

I have question about routing procedure in linux kernel . Below is the version I am using.

[root@server230 ~]# cat /etc/redhat-release 
Red Hat Enterprise Linux Server release 7.1 (Maipo)
[root@server230 ~]# uname -r
3.10.0-229.el7.x86_64

According to tldp , which route to use in routing table is decided using NETMASK.

http://www.tldp.org/LDP/nag2/x-087-2-issues.routing.html

The process for identifying whether a particular destination address matches
a route is a mathematical operation. The process is quite simple, but it
requires an understanding of binary arithmetic and logic: A route matches a
destination if the network address logically ANDed with the netmask precisely
equals the destination address logically ANDed with the netmask.

I have two interfaces(eth0 and eth1) where each interface operates in same subnet and netmask

[root@server230 ~]# ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN 
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
    valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 52:54:00:80:a1:02 brd ff:ff:ff:ff:ff:ff
    inet 192.168.11.230/24 brd 192.168.11.255 scope global eth0
       valid_lft forever preferred_lft forever
    inet6 fe80::5054:ff:fe80:a102/64 scope link 
       valid_lft forever preferred_lft forever
3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 52:54:00:f1:16:b7 brd ff:ff:ff:ff:ff:ff
    inet 192.168.11.231/24 brd 192.168.11.255 scope global eth1
       valid_lft forever preferred_lft forever
    inet6 fe80::5054:ff:fef1:16b7/64 scope link 
       valid_lft forever preferred_lft forever

Routing table is below

[root@server230 ~]# ip route show
default via 192.168.11.1 dev eth0  proto static  metric 100  
192.168.11.0/24 dev eth1  proto kernel  scope link  src 192.168.11.231 
192.168.11.0/24 dev eth0  proto kernel  scope link  src 192.168.11.230  metric 100 

When icmp packet is sent to 192.168.11.2 which is local network, eth1 is used instead of eth0.

[root@server230 ~]# ping -R -c 1 192.168.11.2
PING 192.168.11.2 (192.168.11.2) 56(124) bytes of data.
64 bytes from 192.168.11.2: icmp_seq=1 ttl=64 time=0.804 ms
RR:     192.168.11.231
        192.168.11.2
        192.168.11.2
        192.168.11.231


--- 192.168.11.2 ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 0.804/0.804/0.804/0.000 ms

My question is how does kernel prioritize the route to use when it has multiple interfaces with same subnet and Netmask?

Thank you for reading.

Best Answer

You're not supposed to have the same network configured on multiple interfaces, there's no point in it. If the two interfaces are now connected to the same thing, it's just wrong (things on one either side will think they're in a net with things on the other side, but not be able to reach them), if they are, that thing will probably just use one of the interfaces anyway. I actually don't know if the kernel looks at the metric value or just uses whatever it found first, but it doesn't really matter.

(If you tried doing this to get redundancy look at bonding - that's what linux calls it, others call it other things).