从虚拟机ovf模板导入的虚拟机网络设置会发生改变,网卡会发生改变,所以导致虚拟机启动后网络不能用。
所以要做下面几件事情,网络才会可用:
1 首先查看/etc/udev/rules.d/70-persistent-net.rules文件,在文件最后出现的eth网卡为系统建立的新网卡,以及mac地址。将原来网卡那行注释掉。
2 查看/etc/sysconfig/network-scripts/ifcfg-eth0(1)这个文件,这个文件为原始虚拟机的网络设置
3 将原有ifcfg-eh文件进行改名,改成新的网卡文件
4 对于新的网卡文件,作如下修改:
a 改eth、mac、ip、netmask、gateway
b 重启网络
#modify the real network address! echo "Please input your address:" read IP sed -i "11s/IPADDR=.*/IPADDR=$IP/g" /etc/sysconfig/network-scripts/ifcfg-eth0 echo "Please input your network mask:" read mask sed -i "12s/NETMASK=.*/NETMASK=$mask/g" /etc/sysconfig/network-scripts/ifcfg-eth0 echo "Please input your default gateway:" read gateway sed -i "13s/GATEWAY=.*/GATEWAY=$gateway/g" /etc/sysconfig/network-scripts/ifcfg-eth0 #get the device-file"/etc/udev/rules.d/70-persistent-net.rules" network card mac address mac=`cat /etc/udev/rules.d/70-persistent-net.rules|grep eth1|cut -d ‘,‘ -f 4|cut -d ‘"‘ -f 2|sed -n ‘2p‘` #replace the mac address of the network card file sed -i "2s/HWADDR=.*/HWADDR=$mac/g" /etc/sysconfig/network-scripts/ifcfg-eth0 #modify the network card file mv /etc/sysconfig/network-scripts/ifcfg-eth0 /etc/sysconfig/network-scripts/ifcfg-eth1 sed -i ‘1s/eth0/eth1/‘ /etc/sysconfig/network-scripts/ifcfg-eth1 #masking the nouse network card sed -i ‘/eth0/s/^/#/g‘ /etc/udev/rules.d/70-persistent-net.rules service network restart
时间: 2024-10-08 20:54:34