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

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


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 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 brd 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 brd 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 dev eth0  proto static  metric 100 dev eth1  proto kernel  scope link  src dev eth0  proto kernel  scope link  src  metric 100 

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

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

--- 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.


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).

| improve this answer | |
  • I agree with you. My example was bad. I was studying for my RHCE cert and the text book had this example in it. – Yu Watanabe May 16 '16 at 10:15

If there are many possible lines in routing table, kernel select one with lower METRIC.

In your case, your interface eth0 have metric 100.
Other interface eth1 have default metric (probably 0), so kernel select eth1. (corrected)

| improve this answer | |
  • umm.... according to what you wrote, since 0 is the lower value of 0 and 100 the kernel should select eth1??? not eth0. – GroovyDotCom Nov 13 '17 at 17:16

There is no routing involved here, because the source and destination are in the same IP network. Routing happens on intermediate nodes during the packet's journey from one IP network to another IP network.

Here, the question is about how Linux selects the outbound interface for a particular packet. I don't have exact information about that, but my educated guess is that it depends on the order the interfaces are configured on the system.

However, as Henrik mentioned above, there isn't any good reason to configure two interfaces with two IP addresses on the same network.

| improve this answer | |
  • 1
    Routing still occurs here, link-local routing, its forwarding that does not occur. – Matthew Ife May 16 '16 at 11:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.