shell脚本解决克隆vmware后有网卡冲突的问题

分类:shell编程 阅读:17437 次

克隆vmware后有网卡冲突的问题,每次建多个实验虚拟机的时候都是很重复的事情。因此,有下面的脚本可以快速搞定实验环境的搭建。

克隆后,登陆主机,新建一个net.sh粘贴下面的脚本,然后赋予执行权限(chmod +x)然后运行./net.sh 就可以搞定。

#!/bin/bash sed -i 's/eth0/eth2/g' /etc/sysconfig/network-scripts/ifcfg-eth0 sed -i 's/eth1/eth3/g' /etc/sysconfig/network-scripts/ifcfg-eth1 sed -i '/HWADDR/d' /etc/sysconfig/network-scripts/ifcfg-eth0 sed -i '/HWADDR/d' /etc/sysconfig/network-scripts/ifcfg-eth1 ifconfig eth2 | sed -n '1p' | cut -b 32- >> /etc/sysconfig/network-scripts/ifcfg-eth0 ifconfig eth3 | sed -n '1p' | cut -b 32- >> /etc/sysconfig/network-scripts/ifcfg-eth1 sed -i 's/HWaddr /HWaddr=/g' /etc/sysconfig/network-scripts/ifcfg-eth0 sed -i 's/HWaddr /HWaddr=/g' /etc/sysconfig/network-scripts/ifcfg-eth1 mv /etc/sysconfig/network-scripts/ifcfg-eth0 /etc/sysconfig/network-scripts/ifcfg-eth2 mv /etc/sysconfig/network-scripts/ifcfg-eth1 /etc/sysconfig/network-scripts/ifcfg-eth3

别忘记重启网卡

 service network restart