You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Ubuntu 22.04下双网卡(enp7s0、enp8s0)同时使用时iproute2路由表配置报错的解决求助

Ubuntu 22.04下双网卡(enp7s0、enp8s0)同时使用时iproute2路由表配置报错的解决求助

我在Ubuntu 22.04上想同时用enp7s0和enp8s0这两块网卡,它们各自连了独立的网络。目前默认用的是enp8s0(因为我先插的它的网线),我觉得得配置路由表才能实现双网卡同时工作。

于是我编辑了/etc/iproute2/rt_tables文件,添加了一行:

1 rt2

接着执行了以下几条命令:

ip route add 192.168.0.0/24 dev enp7s0 src 192.168.0.101 table rt2
ip route add default via 192.168.0.1 dev enp7s0 table rt2
ip rule add from 192.168.0.101/32 table rt2
ip rule add to 192.168.0.101/32 table rt2

我的ifconfig输出如下:

enp7s0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.0.101  netmask 255.255.255.0  broadcast 192.168.0.255
        inet6 fe80::9c8b:3fe5:795e:bd32  prefixlen 64  scopeid 0x20<link>
        ether d8:5e:d3:01:84:ed  txqueuelen 1000  (Ethernet)
        RX packets 19214  bytes 18384493 (18.3 MB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 11885  bytes 1705118 (1.7 MB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
        device memory 0xfc700000-fc71ffff

enp8s0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.1.16  netmask 255.255.255.0  broadcast 192.168.1.255
        inet6 2403:6200:89a6:96ee:7aba:94ac:f7e5:421c  prefixlen 64  scopeid 0x0<global>
        inet6 fe80::a09b:20eb:6e61:72b8  prefixlen 64  scopeid 0x20<link>
        inet6 2403:6200:89a6:96ee:33b5:37f2:4af1:bcbb  prefixlen 64  scopeid 0x0<global>
        ether d8:5e:d3:01:84:ee  txqueuelen 1000  (Ethernet)
        RX packets 4578155424  bytes 397941134593 (397.9 GB)
        RX errors 0  dropped 25613  overruns 0  frame 0
        TX packets 9865356056  bytes 14456549029829 (14.4 TB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

但当我执行ip rule show时,出现了这个错误:

Database /etc/iproute2/rt_tables is corrupted at ip route add 192.168.0.0/24 dev enp7s0 src 192.168.0.101 table rt2
0:  from all lookup local
32766:  from all lookup main
32767:  from all lookup default

我该怎么解决这个问题呢?

我猜测可能是没配置/etc/network/interfaces文件,之前查资料说要加这些内容:

auto lo
iface lo inet loopback

allow-hotplug enp7s0
iface enp7s0 inet static
    address 192.168.0.101
    netmask 255.255.255.0
    gateway 192.168.0.1

allow-hotplug enp8s0
iface enp8s0 inet static
    address 192.168.1.16
    netmask 255.255.255.0

不过Ubuntu 22.04好像已经不用这个文件了,改成/etc/netplan了?我在那个目录里只找到01-network-manager-all.yaml,里面内容是:

# Let NetworkManager manage all devices on this system
network:
  version: 2
  renderer: NetworkManager

备注:内容来源于stack exchange,提问作者God of Money

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.23 09:39:35