我正在尝试将本地开发流浪者盒子升级到 CentOS 7.2(从 6.8),但遇到了新的“可预测网络接口名称”的问题。我的 puppet 配置需要 eth0 和 eth1,但它正在获取 enp0s3 和 enp0s8。
我设法通过添加以下内容在 kickstart 文件中禁用可预测的网络接口名称:
bootloader --location=mbr --append="net.ifnames=0"
并删除包biosdevname
现在,当我的流浪盒启动时,它有 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,但使其正常工作?
谢谢
答案1
我在打包程序中添加了一个配置程序脚本,似乎解决了这个问题:
#!/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'
答案2
如何保留 eth0 和 eth1,但使其正常工作?
我相信我可以帮助回答第一部分关于保留eth0
和eth1
(或者至少为您提供一个很好的参考)。根据Linux 中一致的网络设备命名,您应该能够使用手册第 9 节中的以下内容禁用新命名:
安装时禁用
要禁用新命名方案的使用,请在安装过程中(有人参与或自动)
biosdevname=0
在引导命令行上传递内核命令行参数。安装后应在引导命令行上传递该参数,以确保安装后插入的新网络适配器具有传统的“eth”名称。
我的经验是它是否真的有效。例如,参见网络设备命名问题以及 p2p1 和 p3p1 的别名回到 eth0 和 eth1关于超级用户。