Networking
Centos 7 使用 packer/vagrant 禁用可預測的網路介面名稱
我正在嘗試將我們的本地 dev vagrant box 升級到 CentOS 7.2(從 6.8),但遇到了新的“可預測的網路介面名稱”的問題。我的 puppet 配置需要 eth0 和 eth1,但它得到了 enp0s3 和 enp0s8。
我設法通過添加以下內容在 kickstart 文件中禁用了可預測的網路介面名稱:
bootloader --location=mbr --append="net.ifnames=0"
並刪除包 biosdevname
現在,當我的 vagrant box 啟動時,它有 eth0 和 eth1(當我執行 ip -a 時顯示),但我在 /etc/sysconfig/network-scripts/ 中沒有網路腳本(只有 ifcfg-enp0s3 和 ifcfg-lo )。
當 vagrant 啟動這個虛擬機時,它會顯示這個錯誤:
The following SSH command responded with a non-zero exit status. Vagrant assumes that this means the command failed! # Update sysconfig sed -i 's/\(HOSTNAME=\).*/\1vm.example.com/' /etc/sysconfig/network # Update DNS sed -i 's/\(DHCP_HOSTNAME=\).*/\1"vm"/' /etc/sysconfig/network-scripts/ifcfg-* # Set the hostname - use hostnamectl if available echo 'vm.example.com' > /etc/hostname if command -v hostnamectl; then hostnamectl set-hostname --static 'vm.example.com' hostnamectl set-hostname --transient 'vm.example.com' else hostname -F /etc/hostname fi # Remove comments and blank lines from /etc/hosts sed -i'' -e 's/#.*$//' -e '/^$/d' /etc/hosts # Prepend ourselves to /etc/hosts grep -w 'vm.example.com' /etc/hosts || { sed -i'' '1i 127.0.0.1\tvm.example.com\tvm' /etc/hosts } # Restart network service network restart Stdout from the command: /bin/hostnamectl Restarting network (via systemctl): [FAILED] Stderr from the command: Job for network.service failed because the control process exited with error code. See "systemctl status network.service" and "journalctl -xe" for details.
journalctl -xe 顯示:
-- Unit network.service has begun starting up. Oct 11 04:28:59 vm.example.com network[3130]: Bringing up loopback interface: Could not load file '/etc/sysconfig/network-scripts/ifcfg-lo' Oct 11 04:28:59 vm.example.com network[3130]: Could not load file '/etc/sysconfig/network-scripts/ifcfg-lo' Oct 11 04:28:59 vm.example.com network[3130]: Could not load file '/etc/sysconfig/network-scripts/ifcfg-lo' Oct 11 04:28:59 vm.example.com network[3130]: Could not load file '/etc/sysconfig/network-scripts/ifcfg-lo' Oct 11 04:28:59 vm.example.com network[3130]: [ OK ] Oct 11 04:28:59 vm.example.com network[3130]: Bringing up interface enp0s3: Error: Connection activation failed: No suitable device found for this connection. Oct 11 04:28:59 vm.example.com network[3130]: [FAILED] Oct 11 04:28:59 vm.example.com network[3130]: RTNETLINK answers: File exists Oct 11 04:28:59 vm.example.com network[3130]: RTNETLINK answers: File exists Oct 11 04:28:59 vm.example.com network[3130]: RTNETLINK answers: File exists Oct 11 04:28:59 vm.example.com network[3130]: RTNETLINK answers: File exists Oct 11 04:28:59 vm.example.com network[3130]: RTNETLINK answers: File exists Oct 11 04:28:59 vm.example.com network[3130]: RTNETLINK answers: File exists Oct 11 04:28:59 vm.example.com network[3130]: RTNETLINK answers: File exists Oct 11 04:28:59 vm.example.com network[3130]: RTNETLINK answers: File exists Oct 11 04:28:59 vm.example.com network[3130]: RTNETLINK answers: File exists Oct 11 04:28:59 vm.example.com systemd[1]: network.service: control process exited, code=exited status=1 Oct 11 04:28:59 vm.example.com systemd[1]: Failed to start LSB: Bring up/down networking.
如何保留 eth0 和 eth1,但使其正常工作?
謝謝
我在打包程序中添加了一個配置腳本,似乎已經解決了這個問題:
#!/bin/bash mv /etc/sysconfig/network-scripts/ifcfg-enp0s3 /etc/sysconfig/network-scripts/ifcfg-eth0 sed -i -e 's/enp0s3/eth0/' /etc/sysconfig/network-scripts/ifcfg-eth0 bash -c 'echo NM_CONTROLLED=\"no\" >> /etc/sysconfig/network-scripts/ifcfg-eth0'
如何保留 eth0 和 eth1,但使其正常工作?
我相信我可以幫助回答關於保留
eth0
和eth1
(或至少為您提供一個很好的參考)的第一部分。根據Linux 中的一致網路設備命名,您應該能夠使用手冊第 9 節中的以下內容禁用新命名:在安裝期間禁用
要禁用新命名方案,在安裝(有人參與或自動)期間,
biosdevname=0
在引導命令行上傳遞核心命令行參數。該參數應在安裝後在引導命令行中傳遞,以確保安裝後插入的新網路適配器具有傳統的“eth”名稱。這是我的經驗,它是否真的有效。例如,請參閱網路設備命名問題和 p2p1 和 p3p1 的別名返回到超級使用者上的 eth0 和 eth1。