RTNETLINK answers: File exists问题分析

最近在调试以太网时一直出现"RTNETLINK answers: File exists"错误,刚开始一直以为是以太网驱动的问题,以太网采用的是MII接口,phy采用的YT8522,很奇怪的是出现上述错误时,以太网其实工作是正常的。另外一路采用RMII,同样的phy芯片的却没有报这个错误,百思不得其解。

bash 复制代码
root@test:~# ifup -a
[   26.985738] mac030 54200000.gmac eth0: Link is Down
[   27.193736] mac030 54300000.gmac eth1: Link is Down
RTNETLINK answers: File exists
Failed to bring up eth1.

手动单个以太网去配置时,发现每次都是第一个配置的成功,第二个配置的就报上述的错误,如下,先配置eth1,再配置eth0,则eth0配置时报错。

bash 复制代码
root@test:~# ifup eth1
[   24.163714] gmac030 54300000.gmac eth1: Link is Down
root@test:~# 
root@test:~# 
root@test:~# ifup eth0
[   27.285840] mac030 54200000.gmac eth0: Link is Down
RTNETLINK answers: File exists
Failed to bring up eth0.

也就是说谁先配置谁成功,后配置则失败,那么原因究竟是啥呢,网上搜索了好久也没有找到原因,既然这样就直接看ifup的源代码吧,在代码中加上一些打印看看。操作如下:

bash 复制代码
root@test:~# ./ifup eth0
===== do_interface 1 =====
===== lock_interface 1 filename is /run/network/ifstate.eth0 =====
===== lock_interface 3 =====
===== lock_interface 4 =====
===== lock_interface 6 =====
===== lock_interface 7 =====
===== lock_interface 8 =====
===== do_interface 2 current_state is 0 =====
##### out is  #####
===== Configuring interface eth0=eth0 (inet) ======
===== do_interface 3 pidfilename is /run/network/ifup-eth0.pid =====
===== do_interface 4 command is ifup =====
===== do_interface 5 no_act is 0 =====
===== do_interface 6 =====
####### inet _static_up 1 #######
##### out is /sbin/ip addr add 192.168.2.170/255.255.255.0 broadcast 192.168.2.255        dev eth0 label eth0 #####
####### inet _static_up 2 #######
##### out is /sbin/ip link set dev eth0   up #####
####### inet _static_up 3 #######
##### out is  /sbin/ip route add default via 192.168.2.254  dev eth0 onlink  #####
####### inet _static_up 4 #######
===== iface_up 1 result is 1 =====
===== iface_up 2 =====
===== iface_postup 1 =====
===== iface_postup method name is static  =====
####### inet _static_up 1 #######
##### out is /sbin/ip addr add 192.168.2.170/255.255.255.0 broadcast 192.168.2.255        dev eth0 label eth0 #####
####### inet _static_up 2 #######
##### out is /sbin/ip link set dev eth0   up #####
####### inet _static_up 3 #######
[  128.882457] mac030 54200000.gmac eth0: Link is Down
##### out is  /sbin/ip route add default via 192.168.2.254  dev eth0 onlink  #####
####### inet _static_up 4 #######
===== iface_postup 5 =====
===== current_state is 0 failed is 0 =====

先操作eth0成功,接下来操作eth1

bash 复制代码
root@test:~# ./ifup eth1
===== do_interface 1 =====
===== lock_interface 1 filename is /run/network/ifstate.eth1 =====
===== lock_interface 3 =====
===== lock_interface 4 =====
===== lock_interface 6 =====
===== lock_interface 7 =====
===== lock_interface 8 =====
===== do_interface 2 current_state is 0 =====
##### out is  #####
===== Configuring interface eth1=eth1 (inet) ======
===== do_interface 3 pidfilename is /run/network/ifup-eth1.pid =====
===== do_interface 4 command is ifup =====
===== do_interface 5 no_act is 0 =====
===== do_interface 6 =====
####### inet _static_up 1 #######
##### out is /sbin/ip addr add 192.168.1.170/255.255.252.0 broadcast 192.168.3.255        dev eth1 label eth1 #####
####### inet _static_up 2 #######
##### out is /sbin/ip link set dev eth1   up #####
####### inet _static_up 3 #######
##### out is  /sbin/ip route add default via 192.168.1.254  dev eth1 onlink  #####
####### inet _static_up 4 #######
===== iface_up 1 result is 1 =====
===== iface_up 2 =====
===== iface_postup 1 =====
===== iface_postup method name is static  =====
####### inet _static_up 1 #######
##### out is /sbin/ip addr add 192.168.1.170/255.255.252.0 broadcast 192.168.3.255        dev eth1 label eth1 #####
####### inet _static_up 2 #######
##### out is /sbin/ip link set dev eth1   up #####
####### inet _static_up 3 #######
[  230.948350] mac030 54300000.gmac eth1: Link is Down
RTNETLINK answers: File exists
##### out is  /sbin/ip route add default via 192.168.1.254  dev eth1 onlink  #####
===== iface_postup 2 =====
===== 2 failed is 1 =====
===== current_state is 0 failed is 1 =====
Failed to bring up eth1.
root@test:~# 

问题出来了,执行"/sbin/ip route add default via 192.168.1.254 dev eth1 onlink"失败了,打开eth1的network配置文件如下:

bash 复制代码
#iface eth1 inet manual
auto eth1
#allow-hotplug eth1
iface eth1 inet static
address 192.168.1.170
netmask 255.255.255.0
gateway 192.168.1.254
dns-nameservers 192.168.1.240

eth0如下:

bash 复制代码
#iface eth0 inet manual
auto eth0
#allow-hotplug eth0
iface eth0 inet static
address 192.168.2.170
netmask 255.255.255.0
gateway 192.168.2.254
dns-nameservers 192.168.2.240

那问题就在gateway这句话了,两个配置文件中都有这个配置,将eth1中的gateway注释掉就OK了。

相关推荐
ACP广源盛1392462567317 小时前
IX8024与科学大模型的碰撞@ACP#筑牢科研 AI 算力高速枢纽分享
运维·服务器·网络·数据库·人工智能·嵌入式硬件·电脑
Empty-Filled17 小时前
AI生成测试用例功能怎么测:一个完整实战案例
网络·人工智能·测试用例
码云数智-大飞18 小时前
本地部署大模型:隐私安全与多元优势一站式解读
运维·网络·人工智能
jinanwuhuaguo19 小时前
(第二十九篇)OpenClaw 实时与具身的跃迁——从异步孤岛到数字世界的“原住民”
前端·网络·人工智能·重构·openclaw
等风来不如迎风去19 小时前
【win11】最佳性能:fix 没有壁纸,一直黑屏
网络·人工智能
Harvy_没救了19 小时前
【网络部署】 Win11 + VMware CentOS8 + Nginx 文件共享服务 Wiki
运维·网络·nginx
汤愈韬20 小时前
NAT Server 与目的Nat
网络·网络协议·网络安全·security
2401_8734794021 小时前
断网时如何实时判断IP归属?嵌入本地离线库,保障风控不中断
运维·服务器·网络
7ACE21 小时前
Wireshark TS | TLP 超时时间
网络·网络协议·tcp/ip·wireshark·tcpdump
其实防守也摸鱼1 天前
CTF密码学综合教学指南--第三章
开发语言·网络·python·安全·网络安全·密码学