You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多
文档控制台
免费开始使用

Debian 11中无法正常启用第二个物理网卡的问题求助

Debian 11中无法正常启用第二个物理网卡的问题求助

兄弟,我一眼就瞅出你遇到的问题根源啦!你给两个物理网卡都配置了默认网关,但Linux系统默认只能存在一条默认路由,当第二个网卡(ens4)尝试添加自己的默认网关时,就会因为路由表中已经有了ens3的默认路由而报错RTNETLINK answers: File exists,这就是导致ifup失败的核心原因。

解决步骤:

  • 只保留主业务网卡(这里是ens3)的gateway配置,把第二个网卡(ens4)的gateway行删掉
  • 如果你的业务需要通过ens4访问特定网段,可以手动添加静态路由(不需要的话这步跳过)

修改后的/etc/network/interfaces配置示例:

# This file describes the network interfaces available on your system and how to activate them. For more information, see interfaces(5).

source /etc/network/interfaces.d/*

# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
auto ens3
iface ens3 inet static
    address 10.0.0.1/24
    gateway 10.0.0.254
    dns-nameservers 10.230.100.1
    dns-search mydomain.net

# Secondary network interface
auto ens4
iface ens4 inet static
    address 192.168.0.1/24
    # 去掉ens4的gateway配置
    dns-nameservers 10.230.100.1
    dns-search mydomain.net

验证方法:

  1. 重启网络服务:sudo systemctl restart networking.service
  2. 查看网卡状态:ip a,确认ens4已经正常UP
  3. 检查路由表:ip route,会看到只有一条默认路由指向10.0.0.254(ens3的网关)

补充说明:

如果你的场景确实需要两个网卡都能对外走不同的网关,那得配置策略路由(基于源IP或应用来选择路由),但大部分情况下单默认网关就足够满足需求啦。

另外,你手动执行ifdown ens4时提示“interface ens4 not configured”,是因为之前启动失败导致网卡没正确注册到网络管理工具里,修改配置后重新启动就不会有这个问题了。


备注:内容来源于stack exchange,提问作者motorbass

火山引擎 最新活动