A non-transitory machine readable medium storing a program for connecting a location of external machines, outside of a plurality of public cloud datacenters, of an entity to a virtual network that is defined over the plurality of public cloud datacenters, the program comprising sets of instructions for:
- sending a DNS (domain name server) request to identify a particular managed forwarding node (MFN) from a plurality of MFNs in the plurality of public cloud datacenters that are candidate edge MFNs for connecting the location of the external machines to the virtual network, wherein the virtual network is formed by the plurality of MFNs;
- receiving, in response to the DNS request, an identifier that identifies the particular MFN as an ingress node of the virtual network to forward packets from the external machines at the location to other external machines at another location outside of the plurality of public cloud datacenters;
- establishing a network connection between the location of the external machines and the particular MFN in order to connect the location of the external machines to the virtual network;
- performing the sending, receiving and establishing operations after determining that a network connection needs to be established between the location of the external machines and the virtual network;
- and
- repeatedly sending the DNS request to ensure that the particular MFN is an optimal ingress node of the virtual network for the location of the external machines, and upon receiving an identifier of another MFN as the ingress node of the virtual network for the location, establishing a new network connection between the location of the external machines and the other MFN in order to connect the location to the virtual network through the other MFN.