1

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?

Udo G
  • 443
  • 4
  • 9
  • 20
  • Normally, you're not expected to use static addresses in addition to a DHCP-assigned dynamic IP address on the same physical interface... If the two netmasks are identical (the selector in the two IP routes would be the same), then 'metric' could be used to prioritize one route over the other. For differing subnet masks, the more specific one always prevails. – Laszlo Valko Feb 04 '16 at 12:42
  • Actually no, neither the metric nor the subnet mask seems to be relevant. Instead, the order in which the interfaces have been set up seems to make a difference. Changing an interface like `eth0:1` (netmask must change at least once, but can be set back right after) or putting it down and up again apparently moves the interface to the bottom, giving it a lower priority. That is with Linux Kernel 3.19 and is probably implementation-specific and better not to rely on. – Udo G Feb 10 '16 at 17:33

0 Answers0