Linux 裝置管理員 Udev 升級時網卡重新命名問題如何解決

來源:互聯網
上載者:User

故障描述

最近終於更新了下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
}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.