BGP port Numbers

Hi

R1<--------->R2

R1)#router bgp 1

)#neighbor 10.1.12.2 remote-as 2

BGP is using port number 179 which means only one side has to be the TCP server and accept connections from TCP clients with the dst port number 179

but what if R1 has the dst port number 179 and R2 is also has a dst port number 179? which means in this case both side are not going to initiate sending TCP SYN message and both are in the waiting state

or what if R1 has a TCP ephemeral port number and R2 is also has TCP ephemeral port number ?which means here BOTH are trying to initiate the TCP sesstion

what is the mechanism that BGP is using in order to preventing that from happeneing ?
@Network_Eric

Hey Major,

Ports exist on Layer 4 of the OSI, but within a system, ports are used to tell a device what service a packet is destined to. So, if you are a computer, you might be listening for port 67 and this is tied to your DHCP service. This means that when you receive a packet with that port, the network stack will forward the data to that service on the device.

Now, let’s say we want to send a packet. The service assembles a packet and then passes it off to the Network interface stack. Some services use symmetrical ports. So, it might listen and send on the exact same port (same source and destination). Other services use a randomly chosen unused port on the host that that it will uniquely assign to that instance. For instance, your web browser might keep track of each tab by generating a different random port for each tab (different source and destination).

With BGP, when attempting to connect to a server as a client it uses a BGP “client service” (For lack of a better term, this is not official terminology, mainly used to understand how it works) with a randomly generated source port and a destination of port 179, exactly as you described above. However, this does not stop it from running a BGP Listen service on TCP port 179 (Listen is actually what this is called, see BGP Dynamic Neighbors to understand more). Once a TCP connection is established and a device is chosen as a server, the server will no longer send a client request to the other device, instead it will respond to the TCP packet it received on the randomly assigned port number. In this case it would respond back with a source of let’s say 179 and a destination of 5569, or whatever the randomly chosen port was.

It’s worth noting that if BGP is using dynamic BGP neighbors it doesn’t even send client requests, and will only operate as a server.

Basically, the client requesting and the server listening are two separate processes running on the device at the same time, whichever communicates with the neighbor first wins. The same you might have an interface on a router performing a DHCP request, but it could still be a DHCP server for other devices, these are not mutually exclusive.

Barring potential firewall rules, which device is chosen as the server and which device is chosen as the client makes no difference to BGP, unlike OSPF for instance, where the DR placement can be very important.

1 Like