"I always figured that the router would choose the best route."
That's exactly what the router does, it's just that the selection criteria isn't based on what you think is the best route but a set of "rules":
https://www.juniper.net/documentation/us/en/software/junos/vpn-l2/bgp/topics/concept/routing-protocols-address-representation.html#id-10119586__d4e365
This is, by the way, valid for most (if not all) routing platforms, regardless of vendor. Also, the above is only for BGP routes as direct, static, OSPF routes with a lot of other origins will have a more preferred route preference. That means that if you havve an OSPF route to 10.0.0.0/24 and a BGP route to the same prefix, OSPF wins. On the other hand, prefix length always wins, so a BGP route to 10.0.0.0/25 wins over an OSPF route to 10.0.0.0/24. The order is this (well, roughly):
Prefix lenth
Route preference (https://www.juniper.net/documentation/us/en/software/junos/routing-overview/bgp/topics/concept/routing-protocols-default-route-preference-values.html)
Protocol specific selection criteria
I hope this helps!
-------------------------------------------
Original Message:
Sent: 04-15-2025 14:47
From: JOHN MUNOZ
Subject: Change BGP route preference?
I just established BGP with my ISP but I have also had a "direct connect" to AWS. Testing a route to AWS it looks like it's using my ISPs route instead of my direct connect (it's showing up first in the show route command). I'm still trying to learn the intricacies of BGP routing. I always figured that the router would choose the best route. Do I need to set an administrative distance to force my preferred route? Could I possibly be missing a configuration that's keeping the SRX from seeing the best paths? Im seeing in the AS Path, my direct connect has 4 entries and the ISP only has 3.
SRX-1> show route 18.232.0.0
inet.0: 995065 destinations, 1007602 routes (994898 active, 4031 holddown, 0 hidden)
+ = Active Route, - = Last Active, * = Both
18.232.0.0/14 +[BGP/170] 00:28:32, localpref 100
AS path: 14xxx 16509 14618 I, validation-state: unverified
> to x.x.x.x via xe-0/0/17.0
-[BGP/170] 1w1d 23:27:48, MED 10, localpref 100
AS path: 7224 7224 16509 14618 I, validation-state: unverified
> to y.y.y.y via ge-0/0/15.1
------------------------------
JOHN MUNOZ
------------------------------