一般在vmware安装虚拟机只是默认的一块网卡,不过实验需要双网卡,添加后配置文件没有,这个可以复制,问题是添加的网卡uuid不知道,这里我写上解决的步骤:

cd /etc/sysconfig/network-scripts

cp ifcfg-eth0 ifcfg-eth1

把eth1的uuid,MAC这两行删了,

这个是ifcfg-eth0的配置

DEVICE=eth0
HWADDR=00:0C:29:76:F2:2B
TYPE=Ethernet
UUID=946173d6-61d5-452a-b1d0-dabee6373980
ONBOOT=yes
NM_CONTROLLED=yes
BOOTPROTO=none
IPV4_FAILURE_FATAL=yes
DEVICE=eth0
IPADDR=192.168.22.231
PRIFIX=24
GATEWAY=192.168.22.254
DNS1=8.8.8.8
DOMAIN=114.114.114.114
DEFROUTE=yes
IPV6INIT=no
NAME=“System eth0”

下面是ifcfg-eth1配置

DEVICE=eth1
TYPE=Ethernet
ONBOOT=no
NM_CONTROLLED=yes
BOOTPROTO=none
IPV4_FAILURE_FATAL=yes
DEVICE=eth1
IPADDR=192.168.22.232
PRIFIX=24
GATEWAY=192.168.22.254
DNS1=8.8.8.8
DOMAIN=114.114.114.114
DEFROUTE=yes
IPV6INIT=no
NAME=“System eth1”
修改完后

rm -f /etc/udev/rules.d/70-persistent-net.rules

shutdown -r now

service network restart

虚拟机在遇到网卡的问题时,比如重装系统后,网卡不能启动,或者其他未知的问题,把ifcfg-eth0里面的uuid和MAC删除,然后再 rm /etc/udev/rules.d/70-persistent-net.rules 重启,删除的文件重启后系统会自动分配的,所以也不用备份

注意修改ifcfg-eth1的时候,名称也要修改,在本机ping两个ip都可以通,

如果复制ifcfg-eth1网卡时候,MAC没有删,会出现下面的错误提示

service network restart

Shutting down interface eth1: [ OK ]

Shutting down loopback interface: [ OK ]

Bringing up loopback interface: [ OK ]

Bringing up interface eth0: Device eth0 has different MAC address than expected, ignoring.

                                                      [FAILED]

Bringing up interface eth1:

Determining IP information for eth1… done. [ OK ]

附修改的shell

cat fixeth0.sh
if grep -q eth1 /etc/udev/rules.d/70-persistent-net.rules; then
sed -i ‘/eth0/d’ /etc/udev/rules.d/70-persistent-net.rules;
sed -i ‘s/eth1/eth0/g’ /etc/udev/rules.d/70-persistent-net.rules;
ETHERNET=grep eth0 /etc/udev/rules.d/70-persistent-net.rules | awk -F"," '{print $4}' | awk -F"\"" '{print $2}';
echo Ethernet Addr: E T H E R N E T ; s e d − i ′ s / H W A D D R = " . ∗ " / H W A D D R = " ′ ETHERNET; sed -i 's/HWADDR=".*"/HWADDR="' ETHERNET;sedis/HWADDR="."/HWADDR="ETHERNET’"/’ /etc/sysconfig/network-scripts/ifcfg-eth0;
/sbin/start_udev
/sbin/service network restart;
fi

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐