如何强制 ssh 使用具有更高指标的第二个接口?

mir*_*mir 9 ssh bonding crunchbang interface

我有一个Crunchbang VM具有两个接口,eth0并且eth1,其中的每一个连接到的OpenWRT VM(eth010.232.64.20eth110.232.65.20)。我正在使用网络管理器和 DHCP。我的总体目标是拥有多个ssh连接,并将它们与ifenslave.

默认情况下,eth1(出于某种原因)是默认网关:

user@crunchbang:~$ ip ro
default via 10.232.65.1 dev eth1  proto static
10.232.64.0/24 dev eth0  proto kernel  scope link  src 10.232.64.20
10.232.65.0/24 dev eth1  proto kernel  scope link  src 10.232.65.20
Run Code Online (Sandbox Code Playgroud)

我添加了一条路线eth0

user@crunchbang:~$ sudo ip route add default via 10.232.64.1 dev eth0  proto static metric 1
Run Code Online (Sandbox Code Playgroud)

然后我有两条路线:

user@crunchbang:~$ ip ro
default via 10.232.65.1 dev eth1  proto static
default via 10.232.64.1 dev eth0  proto static  metric 1
10.232.64.0/24 dev eth0  proto kernel  scope link  src 10.232.64.20
10.232.65.0/24 dev eth1  proto kernel  scope link  src 10.232.65.20
Run Code Online (Sandbox Code Playgroud)

但是,ssh只能通过eth1以下方式出去:

user@crunchbang:~$ ssh -b 10.232.64.20 user@1.2.3.4
ssh: connect to host 1.2.3.4 port 22: Connection timed out

user@crunchbang:~$ ssh -b 10.232.65.20 user@1.2.3.4
Enter passphrase for key '/home/user/.ssh/id_rsa': 
Run Code Online (Sandbox Code Playgroud)

更改eth0指标后,我有:

user@crunchbang:~$ ip ro
default via 10.232.64.1 dev eth0  proto static  metric 1
default via 10.232.65.1 dev eth1  proto static  metric 2
10.232.64.0/24 dev eth0  proto kernel  scope link  src 10.232.64.20
10.232.65.0/24 dev eth1  proto kernel  scope link  src 10.232.65.20
Run Code Online (Sandbox Code Playgroud)

现在ssh只能通过eth0以下方式出去:

user@crunchbang:~$ ssh -b 10.232.64.20 user@1.2.3.4
Enter passphrase for key '/home/user/.ssh/id_rsa': 

user@crunchbang:~$ ssh -b 10.232.65.20 user@1.2.3.4
ssh: connect to host 1.2.3.4 port 22: Connection timed out
Run Code Online (Sandbox Code Playgroud)

如何强制ssh使用具有更高指标的接口?

编辑

我已经实现并测试了4.2 中的配置Linux 高级路由和流量控制 HOWTO 的多个上行链路/提供商部分的路由。鉴于配置很简单,而且我没有遇到错误,我将只显示代码和结果,并进行最少的解释。

root@crunchbang:~# ip route add 10.232.64.0/24 dev eth0 src 10.232.64.20 table T0
root@crunchbang:~# ip route add default via 10.232.64.1 table T0
root@crunchbang:~# ip route add 10.232.65.0/24 dev eth1 src 10.232.65.20 table T1
root@crunchbang:~# ip route add default via 10.232.65.1 table T1
root@crunchbang:~# ip route flush table main
root@crunchbang:~# ip route add 10.232.64.0/24 dev eth0 src 10.232.64.20
root@crunchbang:~# ip route add 10.232.65.0/24 dev eth1 src 10.232.65.20
root@crunchbang:~# ip rule add from 10.232.64.20 table T0
root@crunchbang:~# ip rule add from 10.232.65.20 table T1
root@crunchbang:~# ip route add default scope global nexthop via 10.232.64.1 dev eth0 weight 1 nexthop via 10.232.65.1 dev eth1 weight 1
Run Code Online (Sandbox Code Playgroud)

以下是生成的路由表:

root@crunchbang:~# ip route show table T0
default via 10.232.64.1 dev eth0 
10.232.64.0/24 dev eth0  scope link  src 10.232.64.20 

root@crunchbang:~# ip route show table T1
default via 10.232.65.1 dev eth1 
10.232.65.0/24 dev eth1  scope link  src 10.232.65.20 

root@crunchbang:~# ip ro
default 
    nexthop via 10.232.64.1  dev eth0 weight 1
    nexthop via 10.232.65.1  dev eth1 weight 1
10.232.64.0/24 dev eth0  scope link  src 10.232.64.20 
10.232.65.0/24 dev eth1  scope link  src 10.232.65.20 
Run Code Online (Sandbox Code Playgroud)

使用该配置,ssh 通过两个接口连接:

user@crunchbang:~$ ssh -b 10.232.64.20 user@1.2.3.4
Enter passphrase for key '/home/user/.ssh/id_rsa': 

user@crunchbang:~$ ssh -b 10.232.65.20 user@1.2.3.4
Enter passphrase for key '/home/user/.ssh/id_rsa': 
Run Code Online (Sandbox Code Playgroud)

但是,看来我确实需要丢失网络管理器。如果有人能解释为什么这是一个坏主意,或警告陷阱,我将不胜感激。

编辑2

删除网络管理器进展顺利。我只有最后一个问题。在启动时加载配置的当前标准方法是什么?

小智 1

首先,你的问题解决方案很好。其次,这取决于操作系统。Crunchbag 基于 Debian,因此这个解决方案可以完成这项工作:

https://serverfault.com/questions/487939/permanently-adding-source-policy-routing-rules

在基于 RHEL 的系统上,还可以添加<ifname>-rule<ifname>-route