主权项 |
1. A routing device, comprising:
a first network interface unit, configured to connect the routing device to a local private network; a second network interface unit, configured to connect the routing device to the Internet; and a processing unit, coupled to the first network interface unit and the second network interface unit, and configured to assign a virtual subnet to a remote routing device for at least one remote host in a remote private network to obtain at least one virtual Internet protocol (IP) address according to the virtual subnet, wherein when a first local host in the local private network transmits a first network packet to a target remote host in the remote private network, the processing unit receives the first network packet through the first network interface unit; encapsulates the first network packet according to a public IP address of the remote routing device to generate a first alternative packet; and delivers the first alternative packet to the Internet through the second network interface unit, wherein the first alternative packet comprises the first network packet, and a destination IP address of the first network packet is the virtual IP address of the target remote host, wherein the processing unit attempts to establish a peer-to-peer connection to the remote routing device through the second network interface unit; determines whether the peer-to-peer connection is successfully established; and delivers a first public IP address and a first public port number of the routing device to the remote routing device through the second network interface unit via a user datagram protocol (UDP) server when the peer-to-peer connection is not successfully established, so as to obtain a second public IP address and a second public port number of the remote routing device, wherein the processing unit locates the second public IP address and the second public port number of the remote routing device corresponding to the virtual IP address according to the virtual IP address obtained by the target remote host in an IP header of the first network packet; encapsulates the first public IP address and the second public address into an IP header of the first alternative packet, and encapsulates the first public port and the second public port into a UDP header of the first alternative packet. |