Hi,
This post mainly analyzes the following issue for your reference.
Why does the ebgp-max-hop 2 command need to be configured when a loopback interface is used to establish an EBGP peer relationship?
Before discussing how to use loopback interface addresses to establish EBGP peer relationships, we need to clarify a misunderstanding: two routers are directly connected. How many hops are there between the loopback addresses of two routers? One, two or three?
For network engineers who have previously configured EBGP neighbors with loopback addresses on Huawei routers, they may not hesitate to say two hops: because when two Huawei routers configuring EBGP peer through loopback addresses, by default the EBGP hop is one, the EBGP peer cannot be established. After the ebgp-max-hop 2 command is configured on the routers, the EBGP peer can be established normally. Therefore, many people think there are two hops between the loopback interfaces: (as the figure show) the first hop of RT1 reaches the physical interface of RT2, and then the second hop reaches the loopback address of RT2. This explanation may seem reasonable, but is it actually the case?

Let's verify it. Perform a ping operation on RT1, specify loopback0 as the source address, the TTL value as 1, and the loopback0 address of RT2 as the destination address. If there are two hops between the two, then when the TTL value is 1, it cannot be successfully pinged. But the actual test results are as follows:
[RT1]ping -a 1.1.1.1 -h 1 2.2.2.2:
PING 2.2.2.2:56data bytes, press CTRL_C to break:
Reply from 2.2.2.2: bytes=56 Sequence=1 ttl=255 time=2 ms:
Reply from 2.2.2.2: bytes=56 Sequence=2 ttl=255 time=2 ms:
Reply from 2.2.2.2: bytes=56 Sequence=3 ttl=255 time=2 ms:
Reply from 2.2.2.2: bytes=56 Sequence=4 ttl=255 time=2 ms:
Reply from 2.2.2.2: bytes=56 Sequence=5 ttl=255 time=2 ms
In the preceding test, when the TTL value is 1, the loopback addresses of the two directly connected routers can be pinged. In addition, the ping reply message returned by the peer end is 255. That is, the ping reply message between the two routers is processed based on the one-hop route forwarding. How do you explain this?
In fact, the forwarding process on the routers is as follows: When the RT1 sends packets, If a valid address of any local interface is used as the source address, the router searches the routing table and forward packet based on the outbound interface. The routing table is used to forward packets, so the processing here can be considered as a hop. After the packet reaches the RT2, the router does not search for the routing table. Instead, the router finds that the destination address of the packet is the local address, even if the destination address is not the address of the inbound interface, the packet is directly sent to the CPU for processing.
Therefore, even if the loopback address of the peer router is pinged, there is only one hop for the forwarding.
Here, you may have a new question. Since the communication between loopback interfaces of two routers only needs to pass through one hop, Why the peer ebgp-max-hop 2 command must be configured when the loopback interfaces are used to establish an EBGP peer relationship?
To answer this question, we must review the conditions for establishing an eBGP peer relationship.
In the product documentation: By default, an EBGP connection can be set up only on a directly-connected physical link.
In fact, there are two conditions here:
By default, the number of hops between EBGP neighbors is 1 hop.
The source addresses on both sides must be on the same network segment.
Everyone is familiar with the first rule here, while the second rule is often overlooked.
These two rules are more clearly seen on Cisco routers:
On Cisco routers, To establish an eBGP peer relationship with the loopback address when the router is directly connected, you do not need to change the maximum number of hops between eBGP peers on, you only need to remove the check on the same network segment. The command is as follows: disable-connected-check.
On Huawei routers, when the peer ebgp-max-hop command is configured, why can an eBGP peer relationship be established? The explanation is as follows: When the command is configured, an eBGP peer relationship can be established between routers through two hops. In this case, the device does not check whether the eBGP peer addresses are in the same network segment.
The peer ebgp-max-hop command configures a BGP device to establish an EBGP peer relationship with a peer on an indirectly-connected network and set the maximum number of hops between the two devices.
Based on the preceding analysis, the following deployment method can be used to establish an EBGP peer relationship between Huawei and C routers through loopback addresses:
On C routers: you need to configure the disable-connected-check command for the EBGP peer. Alternatively, run the ebgp-multihop 2 command.
On Huawei routers: only the ebgp-max-hop 2 command can be used to disable the EBGP peer address consistency check. This command also allows the two routers to establish an EBGP peer relationship.

