Preference of Multiple IP Addresses for same Interface

Hi,
Summary : If we have multiple IP Addresses of different subnets attached to the same interface, which one is given preference and why ?
Scenario:

  1. app1 and app3 in labs for testing out “Networking Basics” were initially in 238 subnet (172.16.238.X) and hence they were easily able to discover each other.
  2. We added new IP address to app03 from different subnet 239 (172.16.239.X) which was bound to eth0 interface (same a 238)
  3. Because of the above change, we were not able to reach app03 from app01 (or jumphost)
  4. WHY ? If we have both 238 and 239 addresses attached to eth0 , they shouldn’t it use to be able to get pinged from both 238 and 239 network devices ?
  5. If not , why ? What is preferences given for particular interface.

Adding the sample IP configuration for both apps as per lab
ip addr of app01

inet 172.16.238.11/24 brd 172.16.238.255 scope global eth0
valid_lft forever preferred_lft forever
inet 172.16.238.15/24 scope global secondary eth0
valid_lft forever preferred_lft forever

ip addr of app03

inet 172.16.238.13/24 brd 172.16.238.255 scope global eth0
valid_lft forever preferred_lft forever
inet 172.16.239.15/24 scope global eth0
valid_lft forever preferred_lft forever

I would appreciate the Reader to help me with the doubts as i couldn’t find satisfying answers to the query on StackExchange or StackOverflow.

Hi @rkathawate098

It’s to do with how the lab is set up. You’ll note that between Q6 where you set the new IPs and Q7 where you have to re-test the ssh, that it is setting things up. The content of /etc/hosts on jump_host is rewitten by the lab setup so that app03 and app04 can be found on the new addreses. I assume it is also changing the virtual switch that the interface is connected to…

Now as to why they don’t work on both addresses. Think about a physical network card. You can plug one ethernet cable into it, which will represent one network range - it can’t represent two networks that are separated by a router at the same time. You have to plug the other end of the network cable into the correct switch for the other IP address/range associated with the network interface (NIC). On virtual machines, that operation is changing the virtual switch that the NIC is connected to - i.e. the one for the 172.16.239.0 network, so the other address is useless until such time as the switch change is reverted.