如何在不同子网的两个IP主机之间发送数据包?
主持人1: 10.10.0.1
主机2: 10.10.1.2
掩码是: 255.255.255.0
如何从主机1向主机2发送数据包?
Host 1:
10.10.0.1
Host 2:
10.10.1.2
Mask is both:
255.255.255.0
How to send a packet from Host 1 to Host 2?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
将主机 1 的默认网关设置为同时位于 10.10.0/24 网络和 10.10.1/24 网络上的网关计算机。然后在网关机器上启用IP转发。
除非它们确实位于同一物理网络上,否则您无法直接发送数据包。如果它们位于不同的物理子网上,您会将数据包发送到哪个 MAC 地址?没有 - 因为主机 2 不在同一物理网络上 - 这就是您将其发送到网关的原因。
如果主机 1 和主机 2 位于同一物理网络上,那么您不需要寻找通用解决方案。在这种情况下,您可以发送 ARP 请求,然后将数据包发送到您从中获得回复的 MAC 地址,它将到达主机 2 - 与通常通过以太网将 TCP/IP 数据包发送到同一网络上的主机的方式相同。
Set the default gateway of Host 1 to a gateway machine that is on both the 10.10.0/24 network and the 10.10.1/24 network. Then enable IP forwarding on the gateway machine.
You can't send the packet directly unless they are really on the same physical network. If they are on different physical subnets what MAC address would you send the packet to? There isn't one - because Host 2 isn't on the same physical network - that's why you send it to gateway instead.
If Host 1 and Host 2 are on the same physical network then you aren't looking for a general solution. In that case you can send an ARP request and then send the packet to the MAC address you get the reply from and it will arrive at Host 2 - the same way TCP/IP packets are usually sent over Ethernet to hosts on the same network.
在您的 PC 或路由器上,您可以添加到其他网络的路由。因此,如果您想要从 PC 或网络上的特定端口发出的路由,您可以添加一条路由,指定所有发送到该目标网络/主机的数据包都从您选择的特定接口发送出去。
当然,到达目的地的数据包也依赖于返回的路由,因此您需要为每个方向添加一个。
在 Windows 中,您可以使用
route
命令在命令行上执行此操作。输入route ?
了解详细信息。例如,在 Allied Telesis 网络路由器上,如果您有权访问路由器的配置,则可以使用
add ip route
命令。如果您可以提供您正在使用的系统和布局的示例,我们也许能够提供更多信息,使您使用起来更加简单。
On your PC or router, you can add routes to other networks. So if you wanted a route out a particular port on your PC or network, you could add a route which specifies that all packets addressed to that destination network/host get sent out a particular interface of your choice.
Naturally the packets getting to their destination rely on a route back as well, so you'll need to add one for each direction.
In Windows, you can do this on the command line with the
route
command. Typeroute ?
for details.On Allied Telesis networking routers, for example, you could use the
add ip route
command if you have access to the router's config.If you can provide an example of the system you're using and the layout, we may be able to give more information that will make it even simpler for you to use.
如果您能看出——两台计算机位于不同的子网中。
对 IP 和掩码执行“逻辑与:
第一个给出 - 10.10.0.0,第二个给出 - 10.10.1.0。这两个是子网的网络地址。您需要将数据包发送到另一个子网的路由器,以便它可以交付
OTOH,您能告诉我们这种情况到底是在哪里出现的吗?了解现实世界的场景可以帮助我们更有效地解决问题
路由
如果您想对路由有深入的了解,那么。您可能需要检查 新闻组 comp 上的此回复.os.linux.networking 处理路由
If you can make out -- Both the computers are on different subnets.
Do a "Logic AND: on IP and Mask:
1st gives - 10.10.0.0 and 2nd gives - 10.10.1.0. These two are the network addresses of the subnet. You need to send the packet to the router of the other subnet so that it can get delivered
OTOH, Can you tell where exactly has this situation arise. Knowing the real world scenario can help us to solve the problem more effciently
Routing
If you want to have a sound knowledge of routing, then you may want to check this reply on newsgroup comp.os.linux.networking dealing with routing