A gateway is essentially an IP address of a network to another network.
For example, network A and network B, network A's IP address range is "192.168.1.1~192." 168.1.254 ", the subnet mask is 255.255.255.0, and the IP address range for Network B is" 192.168.2.1~192. 168.2.254 ", the subnet mask is 255.255.255.0. In the absence of a router, TCP/IP communication between the two networks is not possible, even if two networks are connected on the same switch (or hub), tcp/ The IP protocol also determines that the hosts in two networks are in different networks based on the subnet mask (255.255.255.0). To achieve communication between the two networks, you must pass through the gateway.
If the host in Network a discovers that the destination host for the packet is not on the local network, forwards the packet to its own gateway, which is then forwarded by the gateway to Network B's gateway, and the gateway of Network B is forwarded to a host on network B. The same is true of network B's process of forwarding packets to network A. To achieve communication between the two networks, you must pass through the gateway. If the host in Network a discovers that the destination host for the packet is not on the local network, forwards the packet to its own gateway, which is then forwarded by the gateway to Network B's gateway, and the gateway of Network B is forwarded to a host on network B. The same is true for network B to forward packets to network a so that only the IP address of the gateway is set up, the TCP/IP protocol can realize the communication between different networks. so which IP address is the IP address of the machine? The IP address of the gateway is the IP address of the device with routing capabilities, a router with routing capabilities, a server with a routing protocol enabled (essentially a router), and a proxy server (also equivalent to a router).
Reference URL:
http://zhoutao.blog.51cto.com/425866/93629
Why do we need to set a default gateway