Default gateways
If a TCP/IP computer needs to communicate with a host on another network, it will usually communicate through a device called a router. In TCP/IP terms, a router that is specified on a host, which links the host's subnet to other networks, is called a default gateway. This section explains how TCP/IP determines whether or not to send packets to its default gateway to reach another computer or device on the network.
When a host attempts to communicate with another device using TCP/IP, it performs a comparison process using the defined subnet mask and the destination IP address versus the subnet mask and its own IP address. The result of this comparison tells the computer whether the destination is a local host or a remote host.
If the result of this process determines the destination to be a local host, then the computer will simply send the packet on the local subnet. If the result of the comparison determines the destination to be a remote host, then the computer will forward the packet to the default gateway defined in its TCP/IP properties. It is then the responsibility of the router to forward the packet to the correct subnet.
Troubleshooting
TCP/IP network problems are often caused by incorrect configuration of the three main entries in a computer's TCP/IP properties. By understanding how errors in TCP/IP configuration affect network operations, you can solve many common TCP/IP problems.
Incorrect Subnet Mask: If a network uses a subnet mask other than the default mask for its address class, and a client is still configured with the default subnet mask for the address class, communication will fail to some nearby networks but not to distant ones. As an example, if you create four subnets (such as in the subnetting example) but use the incorrect subnet mask of 255.255.255.0 in your TCP/IP configuration, hosts will not be able to determine that some computers are on different subnets than their own. When this happens, packets destined for hosts on different physical networks that are part of the same Class C address will not be sent to a default gateway for delivery. A common symptom of this is when a computer can communicate with hosts that are on its local network and can talk to all remote networks except those that are nearby and have the same class A, B, or C address. To fix this problem, just enter the correct subnet mask in the TCP/IP configuration for that host.
Incorrect IP Address: If you put computers with IP addresses that should be on separate subnets on a local network with each other, they will not be able to communicate. They will try to send packets to each other through a router that will not be able to forward them correctly. A symptom of this problem is a computer that can talk to hosts on remote networks, but cannot communicate with some or all computers on their local network. To correct this problem, make sure all computers on the same physical network have IP addresses on the same IP subnet. If you run out of IP addresses on a single network segment, there are solutions that go beyond the scope of this article.
Incorrect Default Gateway: A computer configured with an incorrect default gateway will be able to communicate with hosts on its own network segment, but will fail to communicate with hosts on some or all remote networks. If a single physical network has more than one router, and the wrong router is configured as a default gateway, a host will be able to communicate with some remote networks, but not others. This problem is common if an organization has a router to an internal TCP/IP network and another router connected to the Internet.
默认网关
如果 TCP/IP 计算机需要与另一个网络中的主机进行通信,它通常通过称为路由器的设备进行通信。在 TCP/IP 术语中,主机中指定的、用于将主机子网链接到其他网络的路由器称为默认网关。本节解释 TCP/IP 如何确定是否将数据包发送到其默认网关以到达网络中的另一台计算机或设备。
当主机尝试使用 TCP/IP 与另一个设备进行通信时,它会使用已定义的子网掩码和目标 IP 地址针对子网掩码和其自己的 IP 地址进行比较。此比较结果会告诉计算机目标是本地主机还是远程主机。
如果此过程的结果确定目标是本地主机,则计算机只将数据包发送到本地子网。如果比较结果确定目标是远程主机,则计算机将数据包转发到其 TCP/IP 属性中定义的默认网关。然后,路由器负责将数据包转发到正确的子网。
疑难解答
TCP/IP 网络问题通常是由计算机的 TCP/IP 属性中三个主要条目的错误配置导致的。了解 TCP/IP 配置中的错误如何影响网络操作后,您可以解决许多常见 TCP/IP 问题。
错误的子网掩码:如果网络将默认掩码外的其他子网掩码用于其地址类,而客户端仍使用该地址类的默认子网掩码进行配置,则可以与远程网络进行通信但无法与某些附近网络进行通信。例如,如果创建四个子网(例如在子网配置示例中),但是在 TCP/IP 配置中使用错误的子网掩码 255.255.255.0,则主机将无法确定某些计算机是否在与它们自己的子网不同的子网中。当发生此情况时,发送到作为相同 C 类地址一部分的不同物理网络中的主机的数据包将不会发送到默认网关来进行传送。此问题的常见症状是计算机可以与其本地网络中的主机以及所有远程网络进行通信,但无法与位置在附近并具有相同的 A、B 或 C 类地址的网络进行通信。要解决此问题,只需在该主机的 TCP/IP 配置中输入正确的子网掩码。
错误的 IP 地址:如果将那些 IP 地址在本地网络的不同子网中的计算机放在一起,则它们无法进行通信。它们会尝试通过路由器相互发送数据包,而该路由器却无法正确转发这些数据包。此问题的症状是计算机可以与远程网络中的主机进行通信,但是无法与其本地网络中的某些或全部计算机通信。要解决此问题,请确保同一物理网络中的所有计算机具有同一 IP 子网中的 IP 地址。如果一个网段中的 IP 地址已用完,还可使用一些解决方案进行处理,但已超出本文范围。
错误的默认网关:使用错误的默认网关配置的计算机能够与其自己网段中的主机进行通信,但是无法与某些或全部远程网络中的主机进行通信。如果一个物理网络有多个路由器,且将错误的路由器配置为默认网关,则主机能够与某些远程网络进行通信,但是无法与其他远程网络进行通信。如果组织中有一个路由器连接到内部 TCP/IP 网络,另一个路由器连接到 Internet,则此问题很常见。