故障描述
最近終於更新了下gentoo,重啟發現我的eth0網卡啟動失敗:
* Bringing up interface eth0
* ERROR: interface eth0 does not exist
* Ensure that you have loaded the correct kernel module for your hardware
* ERROR: net.eth0 failed to start
而啟動某些我常用的服務,比如mongodb,也報錯:
~ # /etc/init.d/mongodb restart
* Bringing up interface eth0
* ERROR: interface eth0 does not exist
* Ensure that you have loaded the correct kernel module for your hardware
* ERROR: net.eth0 failed to start
* ERROR: cannot start mongodb as net.eth0 would not start
竟然也需要啟動網卡?
查看核心和dmesg:
查看核心模組已經選中,而且以前eth0也有,再看dmesg
dmesg |grep network
[ 74.261872] systemd-udevd[14259]: renamed network interface wlan0 to wlp2s0
[ 74.391865] systemd-udevd[14259]: renamed network interface eth0 to enp0s4
原來被重新命名了
為什嗎?
從udev-197將自動分配更好的介面名字,具體解釋請看[PredictableNetworkInterfaceNames] (http://www.freedesktop.org/wiki/Software/systemd/PredictableNetworkInterfaceNames),
解決辦法,有三種
臨時辦法,重啟還是會失效
ifrename -i enp0s4 -n eth0 #修改網卡名字變成原來的eth0
使用新的名字
rm /etc/init.d/net.eth0 #刪除不存在的引用
localhost ~ # rc-update delete net.eth0 default #刪除不存在的開機啟動
* service net.eth0 removed from runlevel default
localhost ~ # rc-update add net.enp0s4 default #使用新名字
重設udev的rules,還是用原來的方法
ln -s /dev/null /etc/udev/rules.d/80-net-name-slot.rules
第二種,和第三種需要重啟
啟動應用為什麼也需要啟動應該啟動的網卡
查看/etc/init.d/mongodb指令碼,發現是因為depend,一般的初始化指令碼結構是
#!/sbin/runscript
depend() {
(依賴關係資訊)
}
start() {
(啟動服務所必需的命令)
}
stop() {
(停止服務所必需的命令)
}
restart() {
(重啟服務所必需的命令)
}
比如 mongodb 的依賴是
depend() {
need net #需要依賴net.X
}