I have Linux devices with a single ethernet interface and two IP adresses.
The first (eth0
) is statically configured to 10.1.1.146/24
.
The second (eth0:1
) is configured via DHCP and it may happen that it gets a similar IP like 10.1.1.233/16
, meaning that the subnets overlap.
The routing table looks like this:
# ip route show
default via 10.1.1.11 dev eth0
10.1.0.0/16 dev eth0 proto kernel scope link src 10.1.1.233
10.1.1.0/24 dev eth0 proto kernel scope link src 10.1.1.146
When two of those devices are in the same network it is obvious that the 10.1.1.146
address causes a collision and should not be used. The DHCP address should be used. The 10.1.1.146 is intended for 1-to-1 connections.
Unfortunately, when doing simple things like ping 10.1.1.1
or when trying to reach the Internet, then the Kernel chooses to use the ...146 IP address as source in such a situation. AFAIK that is because it prefers the /24 network since it's smaller.
Question: Can I somehow give the DHCP subnet precedence (perhaps via some ip
command usage), even if there is another subnet that qualifies?