A method for obtaining a route according to a requirement, comprising: receiving, by a first gateway, a first packet, wherein the first packet comprises a first Internet Protocol, IP, address; determining, by the first gateway, a first virtual extensible local area network, VXLAN, network identifier, VNI, corresponding to a port receiving the first packet; determining, by the first gateway, a forwarding table according to a mapping including the first VNI and the forwarding table; and searching, by the first gateway, the forwarding table for a next hop of the first IP address; wherein when the search fails, the method further comprises: searching, by the first gateway, a mapping table storing a mapping between multiple VNIs and multiple gateways for at least one gateway mapped to the VNI of the first packet, wherein a host identified by the VNI is allowed to connect to the at least one gateway mapped to the VNI in the mapping table; sending, by the first gateway, a second packet to the at least one gateway, wherein the second packet carries the first IP address, and the second packet is used to instruct a gateway receiving the second packet to determine whether a host identified by the first IP address accesses a network by using the gateway receiving the second packet; receiving, by the first gateway, a third packet from a second gateway, wherein the second gateway is one of the at least one gateway, and the third packet is used to instruct the host identified by the first IP address to access the network by using the second gateway; and writing, by the first gateway, an address of the second gateway into the forwarding table as a next hop address of the first IP address. receiving, by a first gateway, a first packet, wherein the first packet comprises a first Internet Protocol, IP, address; determining, by the first gateway, a first virtual extensible local area network, VXLAN, network identifier, VNI, corresponding to a port receiving the first packet; determining, by the first gateway, a forwarding table according to a mapping including the first VNI and the forwarding table; and searching, by the first gateway, the forwarding table for a next hop of the first IP address; wherein when the search fails, the method further comprises: searching, by the first gateway, a mapping table storing a mapping between multiple VNIs and multiple gateways for at least one gateway mapped to the VNI of the first packet, wherein a host identified by the VNI is allowed to connect to the at least one gateway mapped to the VNI in the mapping table; sending, by the first gateway, a second packet to the at least one gateway, wherein the second packet carries the first IP address, and the second packet is used to instruct a gateway receiving the second packet to determine whether a host identified by the first IP address accesses a network by using the gateway receiving the second packet; receiving, by the first gateway, a third packet from a second gateway, wherein the second gateway is one of the at least one gateway, and the third packet is used to instruct the host identified by the first IP address to access the network by using the second gateway; and writing, by the first gateway, an address of the second gateway into the forwarding table as a next hop address of the first IP address. searching, by the first gateway, a mapping table storing a mapping between multiple VNIs and multiple gateways for at least one gateway mapped to the VNI of the first packet, wherein a host identified by the VNI is allowed to connect to the at least one gateway mapped to the VNI in the mapping table; sending, by the first gateway, a second packet to the at least one gateway, wherein the second packet carries the first IP address, and the second packet is used to instruct a gateway receiving the second packet to determine whether a host identified by the first IP address accesses a network by using the gateway receiving the second packet; receiving, by the first gateway, a third packet from a second gateway, wherein the second gateway is one of the at least one gateway, and the third packet is used to instruct the host identified by the first IP address to access the network by using the second gateway; and writing, by the first gateway, an address of the second gateway into the forwarding table as a next hop address of the first IP address.