如何使用两个路由器将流量从子网 A 路由到子网 B

1 networking router routing

我需要有关如何将流量从路由器 A 路由到路由器 B 的帮助。

路由器 A 的子网为 10.10.32.0/24,需要将流量发送到子网为 10.20.64.0/22 的路由器 B。

路由器 B 后面的用户无权访问路由器 A 网络。

Router AI 上有以下配置选项:

Destination IP / Mask:
Gateway:
Interface:
Run Code Online (Sandbox Code Playgroud)

目标 IP/掩码将是路由器 B 的 10.20.64.0/22?

接口是10.10.32.1吗?

最后,网关是什么?

dir*_*rkt 5

通常,您不会将流量“从路由器 A 发送到路由器 B”来连接子网。相反,您可以设置一个连接到两个子网的路由器。该路由器可以在两个子网之间转发数据包(这是“路由器”的原始定义)。

因此,路由器没有“网关”(这是典型的客户端配置,网关指向路由器)。相反,它具有两个子网的路由。此外,两个子网中的所有客户端都必须具有正确的路由(除非该路由器是所有客户端的默认路由)。

You certainly can use two routers to connect two subnets, connecting only the routers to each other, but it's unnecessarily complicated.

Note that "home routers" can in principle do all of this, but their firmware is often only tailored to connect a single subnet to an ISP. You can flash most home routers with open source firmware like OpenWRT, however, so you can set up the subnets properly.

Edit

If you are using business class routers, you shouldn't have trouble setting the routing table.

As I wrote, the correct configuration is to use a single router X to route between both segments:

       10.10.32.0/24      Gateway         10.20.64.0/22
                             |
            |             +++++++              |
            |             +     +              |
            | ............+  X  +............. | 
            | 10.10.32.1  +     + 10.20.64.1   |
            |             +++++++              |
            |                                  |
Run Code Online (Sandbox Code Playgroud)

This means each segment can set X as default gateway, and all is simple and easy. This even works if the /24 and the /22 net should get different gateways (which then both connect up to X).

If you insist on making things complicated, here you go: If A is the default gateway for one segment, and B for the other, then as soon as you use e.g. A to to connect them

       10.10.32.0/24      Gateway 1        10.20.64.0/22
                             |
            |             +++++++              |
            |             +     +              |
            | ............+  A  +............. | 
            | 10.10.32.1  +     + 10.20.64.2   |
            |             +++++++              |
            |                                  |
            |                                  |
            |             +++++++              |
            |             +     +              |
            |             +  B  +............. | 
            |             +     + 10.20.64.1   |
            |             +++++++              |
                             |
                          Gateway 2
Run Code Online (Sandbox Code Playgroud)

then the 10.20.64.0/22 segment (i.e., every single host on it) now needs two routes: One default route to B, and one route for 10.10.32.0/24 via 10.20.64.2 to A. This means you either get to install static routes on all hosts on the /22 segment, or you have to distribute routes via DHCP (and pray all hosts accept them).

Or, if you just give B a static route, it will mean every packet has to travel twice through the segment, halving bandwidth. ICMP REDIRECT messages may (or may not) alleviate this, depending on the OS's in use.

You can also make it complicated by connecting the routers between themselves:

       10.10.32.0/24      Gateway 1        10.20.64.0/22
                             |
            |             +++++++              |
            |             +     +              |
            | ............+  A  +              | 
            | 10.10.32.1  +     +              |
            |             +++++++              |
            |                | 192.168.1.3     |
            |                |                 |
            |    192.168.1.2 |                 |
            |             +++++++              |
            |             +     +              |
            |             +  B  +............. | 
            |             +     + 10.20.64.1   |
            |             +++++++              |
                             |
                          Gateway 2
Run Code Online (Sandbox Code Playgroud)

This means you have a third segment with its own IP range. Now static routes on A and B suffice.

Are you sure you want one of the complicated configurations? What are your reasons for wanting it?

Users behind Router B do not have access to Router A network.

这不会影响路由:为了正确连接,数据包必须双向传输。您需要执行的是防火墙规则,具体取决于您最终所在的组织。这是一个完全不同的主题。

TL;DR:如果你想路由,你需要路由表。“网关、掩码和接口设置是什么?” 说明你还没有理解问题所在。找出在路由器上设置路由的位置。