如何 ping 备份接口?

如何 ping 备份接口?

这是我的网络配置:

bond interface 192.168.101.50/24 has two salaves: eth1 (192.168.101.1) that is connected to 192.168.101.2 and eth2 (192.168.101.10) that is connected to 192.168.101.11.

我在active-backup中创建了一个bond接口bond0:

bond0     Link encap:Ethernet  HWaddr 00:E0:4C:48:09:36
          inet addr:192.168.101.50  Bcast:0.0.0.0  Mask:255.255.255.0
          inet6 addr: fe80::2e0:4cff:fe48:936/64 Scope:Link
          UP BROADCAST RUNNING MASTER MULTICAST  MTU:1500  Metric:1
          RX packets:70 errors:0 dropped:0 overruns:0 frame:0
          TX packets:205 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:4968 (4.8 KiB)  TX bytes:14126 (13.7 KiB)

然后我有两个以太网接口

eth1      Link encap:Ethernet  HWaddr 00:E0:4C:48:09:36
          inet addr:192.168.101.1  Bcast:192.168.101.255  Mask:255.255.255.0
          UP BROADCAST RUNNING SLAVE MULTICAST  MTU:1500  Metric:1
          RX packets:84 errors:0 dropped:0 overruns:0 frame:0
          TX packets:218 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:5764 (5.6 KiB)  TX bytes:17132 (16.7 KiB)

eth2      Link encap:Ethernet  HWaddr 00:E0:4C:48:09:36
          inet addr:192.168.101.10  Bcast:192.168.101.255  Mask:255.255.255.0
          UP BROADCAST RUNNING SLAVE MULTICAST  MTU:1500  Metric:1
          RX packets:41 errors:0 dropped:0 overruns:0 frame:0
          TX packets:88 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:2760 (2.6 KiB)  TX bytes:6412 (6.2 KiB)

然后我定义了一个多队列调度,定义了两个队列:eth1 的队列 1 和 eth2 的队列 2。规则如下:

tc filter add dev bond0 protocol ip parent 1: prio 1 u32 match ip \
        dst 192.168.101.2 action skbedit queue_mapping 1
tc filter add dev bond0 protocol ip parent 1: prio 1 u32 match ip \
        dst 192.168.101.11 action skbedit queue_mapping 2

这是实际的配置:

9: eth1: <BROADCAST,MULTICAST,SLAVE,UP,LOWER_UP> mtu 1500 qdisc fq_codel master bond0 state UP mode DEFAULT group default qlen 1000
    link/ether 00:e0:4c:48:09:36 brd ff:ff:ff:ff:ff:ff promiscuity 0 minmtu 68 maxmtu 9194
    bond_slave state ACTIVE mii_status UP link_failure_count 0 perm_hwaddr 00:e0:4c:48:08:10 queue_id 1 addrgenmode eui64 numtxqueues 1 numrxqueues 1 gso_max_size 16354 gso_max_segs 65535
    RX: bytes  packets  errors  dropped missed  mcast
    5764       84       0       0       0       0
    RX errors: length   crc     frame   fifo    overrun
               0        0       0       0       0
    TX: bytes  packets  errors  dropped carrier collsns
    17132      218      0       0       0       0
    TX errors: aborted  fifo   window heartbeat transns
               0        0       0       0       16
14: eth2: <BROADCAST,MULTICAST,SLAVE,UP,LOWER_UP> mtu 1500 qdisc fq_codel master bond0 state UP mode DEFAULT group default qlen 1000
    link/ether 00:e0:4c:48:09:36 brd ff:ff:ff:ff:ff:ff promiscuity 1 minmtu 68 maxmtu 9194
    bond_slave state BACKUP mii_status UP link_failure_count 0 perm_hwaddr 00:e0:4c:48:09:36 queue_id 2 addrgenmode eui64 numtxqueues 1 numrxqueues 1 gso_max_size 16354 gso_max_segs 65535
    RX: bytes  packets  errors  dropped missed  mcast
    2760       41       0       0       0       0
    RX errors: length   crc     frame   fifo    overrun   nohandler
               0        0       0       0       0       5
    TX: bytes  packets  errors  dropped carrier collsns
    6412       88       0       0       0       0
    TX errors: aborted  fifo   window heartbeat transns
               0        0       0       0       4

我以为定义多队列模式后,我能够 ping 到连接到 BACKUP 接口的设备 192.168.101.11(通过 eth2)。但是没有办法 ping 它。有没有办法 ping 到连接到 BACKUP 接口的设备?我无法设置状态 ACTIVE,我需要在 eth2 处于备份状态时 ping。非常感谢。

答案1

一种相对简单的方法是添加静态路由。

例如:WAN 1 网关 IP 为:1.2.3.4 WAN 1 网关 IP 为:4.3.2.1

/ip 路由添加距离=1 目标地址=8.8.8.8 网关=1.2.3.4 添加距离=1 目标地址=8.8.4.4 网关=4.3.2.1

现在您可以放心,对 Google 主 DNS 8.8.8.8 的 ping 操作将从 WAN1 出站,而对 Google 辅助 DNS 8.8.4.4 的 ping 操作将从 WAN2 出站,如果其中一个发生故障,则对该 DNS 的 ping 操作将会失败。

有更优雅的解决方案,但这是一种快捷的方法。

相关内容