使用两个接口进行出站流量负载平衡

使用两个接口进行出站流量负载平衡

我们在一台服务器上有两个接口,为 icecast 流提供服务,其配置如下:

rfitz@streamer:~$ cat /etc/network/interfaces auto lo iface lo inet loopback

auto eth0
iface eth0 inet static
    address 192.168.1.9
    netmask 255.255.255.0
    network 192.168.1.0
    gateway 192.168.1.1

auto eth1
iface eth1 inet static
    address 192.168.7.2
    netmask 255.255.255.0
    network 192.168.7.0
    gateway 192.168.7.1

由此得出以下路由表:

Destination     Gateway         Genmask         Flags Metric Ref    Use 
Iface
192.168.7.0     0.0.0.0         255.255.255.0   U     0      0        0 eth1
192.168.1.0     0.0.0.0         255.255.255.0   U     0      0        0 eth0
0.0.0.0         192.168.7.1     0.0.0.0         UG    100    0        0 eth1
0.0.0.0         192.168.1.1     0.0.0.0         UG    100    0        0 eth0

我们使用 rsync 将文件传输到另一台服务器,这些出站连接现在经常停滞,无法完成传输。如果我从 eth1 中删除网关,则 rsync 不再停滞,但入站流量不会到达服务器,没有响应。删除 eth1 网关后,我尝试添加静态路由,如下所示:

route add -net 192.168.7.0 netmask 255.255.255.0 gw 192.168.7.1

rfitz@streamer:~$ route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
192.168.7.0     192.168.7.1     255.255.255.0   UG    0      0        0 eth1
192.168.7.0     0.0.0.0         255.255.255.0   U     0      0        0 eth1
192.168.1.0     0.0.0.0         255.255.255.0   U     0      0        0 eth0
0.0.0.0         192.168.1.1     0.0.0.0         UG    100    0        0 eth0

但这无助于允许 eth1 上的入站流量。有人可以建议如何配置它吗,如何让 rsync 不会因两个网关而停滞,或者如果仅使用一个网关则允许入站流量?

一切运行正常,直到我们在该路由器停止服务时暂时放弃 eth1。我确实备份了接口文件,它使用了两个网关,我们在出站 rsync 方面没有任何问题,当我们将 eth1 网关重新联机并恢复接口文件时,此过程中一定出现了其他问题。

答案1

在您首次设置 2 个默认网关时,仅使用第一个(192.168.7.1):每个路由表只能有一个活动的默认网关。

如果您想使用 2 个默认网关,您将需要创建 2 个不同的路由表并使用基于策略的路由来定义何时使用每个路由表。

相关内容