将板载以太网与 USB 调制解调器加密狗绑定

将板载以太网与 USB 调制解调器加密狗绑定

我有一个 RaspberryPi 3b+,上面有 raspbian 操作系统。

我正在尝试将板载以太网与 USB 调制解调器加密狗(华为 E3372、HiLink fw)绑定。

问题是当以太网电缆关闭时,网关默认路由保持不变,而不是加密狗的路由。

具有 usb_modeswitch 的加密狗本身成为 eth1 接口。

以下是配置:

# cat /etc/modules
# /etc/modules: kernel modules to load at boot time.
#
# This file contains the names of kernel modules that should be loaded
# at boot time, one per line. Lines beginning with "#" are ignored.

bonding

# cat /etc/modprobe.d/bonding.conf
options bonding fail_over_mac=active mode=active-backup primary=eth0 primary_reselect=always

# cat /etc/network/interfaces.d/0_lo
auto lo
iface lo inet loopback

# cat /etc/network/interfaces.d/10_eth0
auto eth0
allow-hotplug eth0
iface eth0 inet manual
    bond-master bond0
    bond-primary bond0

# cat /etc/network/interfaces.d/11_eth1
auto eth1
allow-hotplug eth1
iface eth1 inet manual
    bond-master bond0
    pre-up sleep 15 #it needs time for raspi to obtain an IP from the dongle

# cat /etc/network/interfaces.d/20_bond0
auto bond0
iface bond0 inet manual
    bond-slaves           none
    bond-miimon           200
    bond-updelay          200
    bond-downdelay        200
    dns-nameservers       8.8.8.8
    dns-nameservers       8.8.4.4

# cat /etc/dhcpcd.conf
...
denyinterfaces eth0 eth1
...

# ifconfig
bond0: flags=5187<UP,BROADCAST,RUNNING,MASTER,MULTICAST>  mtu 1500
        inet 192.168.1.103  netmask 255.255.255.0  broadcast 192.168.1.255
        inet6 aaaa::aaaa:aaaa:aaaa:aaaa  prefixlen 64  scopeid 0x20<link>
        ether XX:XX:XX:XX:XX:XX  txqueuelen 1000  (Ethernet)
        RX packets 82  bytes 17140 (16.7 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 91  bytes 13715 (13.3 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

eth0: flags=6211<UP,BROADCAST,RUNNING,SLAVE,MULTICAST>  mtu 1500
        ether XX:XX:XX:XX:XX:XX  txqueuelen 1000  (Ethernet)
        RX packets 58  bytes 8247 (8.0 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 91  bytes 13715 (13.3 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

eth1: flags=6211<UP,BROADCAST,RUNNING,SLAVE,MULTICAST>  mtu 1500
        ether YY:YY:YY:YY:YY:YY  txqueuelen 1000  (Ethernet)
        RX packets 24  bytes 8893 (8.6 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 8  bytes 600 (600.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 8  bytes 600 (600.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

wlan0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.253.1  netmask 255.255.255.0  broadcast 192.168.253.255
        inet6 ssss::ssss:ssss:ssss:ssss  prefixlen 64  scopeid 0x20<link>
        ether ZZ:ZZ:ZZ:ZZ:ZZ:ZZ  txqueuelen 1000  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 29  bytes 4600 (4.4 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

# route
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
default         192.168.1.254   0.0.0.0         UG    202    0        0 bond0
192.168.1.0     0.0.0.0         255.255.255.0   U     202    0        0 bond0
192.168.253.0   0.0.0.0         255.255.255.0   U     304    0        0 wlan0

# cat /proc/net/bonding/bond0
Ethernet Channel Bonding Driver: v3.7.1 (April 27, 2011)

Bonding Mode: fault-tolerance (active-backup) (fail_over_mac active)
Primary Slave: eth0 (primary_reselect always)
Currently Active Slave: eth0
MII Status: up
MII Polling Interval (ms): 200
Up Delay (ms): 200
Down Delay (ms): 200

Slave Interface: eth0
MII Status: up
Speed: 1000 Mbps
Duplex: full
Link Failure Count: 0
Permanent HW addr: XX:XX:XX:XX:XX:XX
Slave queue ID: 0

Slave Interface: eth1
MII Status: up
Speed: Unknown
Duplex: Unknown
Link Failure Count: 0
Permanent HW addr: YY:YY:YY:YY:YY:YY
Slave queue ID: 0

# dmesg | grep bond
[    4.686567] IPv6: ADDRCONF(NETDEV_UP): bond0: link is not ready
[    4.735082] bond0: making interface eth0 the new active one
[    4.736341] bond0: Enslaving eth0 as an active interface with an up link
[    4.737083] IPv6: ADDRCONF(NETDEV_CHANGE): bond0: link becomes ready
[   20.709485] bond0: Enslaving eth1 as a backup interface with an up link

情况1。以太网电缆, USB 加密狗输入。

两个 ethX 接口均已启动,默认路由网关为 192.168.1.254。网络工作正常!

案例2。以太网电缆出去, USB 加密狗输入。

eth0 接口已关闭,eth1 已开启,默认路由网关保持不变 192.168.1.254。互联网不是在职的。

当我放入denyinterfaces bond0/etc/dhcpcd.conf时,根本没有可用的默认路由,并且该接口无法获取任何IP。

我相信问题出在网关上。有谁知道为什么会发生这种情况。提前致谢!

相关内容