1. A method comprising: determining that a dynamic routing protocol is enabled for a centralized routing component of a logical router, wherein the dynamic routing protocol allows the centralized routing component to exchange routes with at least one physical router; based on the determination that the dynamic routing protocol is enabled, determining whether a router identifier was previously stored for the centralized routing component; when a router identifier was previously stored for the centralized routing component, assigning the stored router identifier as a router identifier for the centralized routing component to use for the dynamic routing protocol only when the stored router identifier matches one of a set of valid addresses for the centralized routing component; and when the centralized routing component does not have a previously stored router identifier that matches one of the set of valid addresses, assigning one of the set of valid addresses as the router identifier for the centralized routing component to use for the dynamic routing protocol according to a hierarchy among the set of valid addresses.