Re: loopback and IP source

From: Benoit Chesneau <benoitc_at_enki-multimedia.eu>
Date: Wed, 15 Nov 2023 09:29:25 UTC
This makes sense. Thanks for the links!

Benoît
On Saturday, November 11th, 2023 at 12:03, Zhenlei Huang <zlei@FreeBSD.org> wrote:

>> On Nov 11, 2023, at 5:56 PM, Benoit Chesneau <benoitc@enki-multimedia.eu> wrote:
>>
>> Is there a way to ensure that the IP set in loopback on the rc.conf is always used as source for routing. I setup it like this:
>>
>> ```
>> cloned_interfaces="lo1"
>> ifconfig_lo1="inet 195.24.245.226/32 up"
>> ifconfig_lo1_ipv6="inet6 2a12:5541:1:1::3/128"
>> ```
>>
>> and others IP are set on interfaces or vlans. All routes informations are fetched via BGP. The strange thing is that when I do a ping to `1.1.1.1`` this work (and pass via one of the vlan through the transit). But when I do a ping to another IP going through an IX the ping only work when I force the source using `-S`: `ping -S $MY_IP $OTHER_IP` . Is there something to do ? How to investigate such issue?
>
> That is expected behavior.
>
> I'll explain IPv4 source ip selection shortly.
> For applications that do not set the source IP address, the source IP is selected at best effort.
> This "best effort" is choosing a IP nearest (lowest metric) to target. Apparently an IP address on
> loopback interfaces are "further" than any IP addresses on the outgoing interface.
>
>> Is there something to do ? How to investigate such issue?
>
> You can refer to RFC 1122 section 3.3.4.3 [1] for IPv4 and RFC 6724 [2] for IPv6.
>
> 1. https://datatracker.ietf.org/doc/html/rfc1122#section-3.3.4.3
> 2. https://datatracker.ietf.org/doc/html/rfc6724
>
>> Benoît
>
> Best regards,
> Zhenlei