VMware VSphere modifies MAC address scripts after creating virtual machines from Templates

Source: Internet
Author: User

#!/bin/bash#################### #Author: jncheng   # #Vsersion: 20150402 ##################### source /etc/profile###################################################################################### ################# #List  the system eth ' s mac-address####################################### ############################################################## #echo   "this mac-address is  In file /etc/udev/rules.d/70-persistent-net.rules "i=0while [  $i  -lt 5 ]  do grep  eth$i /etc/udev/rules.d/70-persistent-net.rules > /root/ mac.txt   if [ $? = 0 ]; then       hwaddr2=$ (awk  ' {print $4} '  /root/mac.txt |awk -F ==  ' {print $2} '   |awk -f \ "  ' {print $2} ')       ethnum=$ (awk  ' {print  $7} '  MAC.TXT&NBsp;|awk -f =  ' {print $2} '  |awk -f \ "  ' {print $2} ')        echo  "$ETHNUM  MAC is   $HWADDR 2"    else    echo  "Can ' T find other eth"    break   fi i= $[i+1] doneecho  "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" echo  "" # # #这里将模板宿主机的物理地址显示出来, tell this MAC address is not available. Because when you clone a template through a virtual host, the MAC address of the previous NIC on the host is saved in the template. Modify it according to the MAC address in the real template. echo  "Mac-address 00:50:56:ae:80:b8 can ' T use!!!!!!!!!!!!!!!!!!!!" echo  "" ################################################################################################## ####### #Modify  the IP and MAC addresss                                                                            ## ####################################################################################################### #read  -p  "Please input which eth number you will modify (0-4):"   input_ethnumgrep  -vi 00:50:56:ae:80:b8 /etc/udev/rules.d/70-persistent-net.rules | grep eth$input_ethnum > /root/mac.txtethnumber=$ (awk  ' {print $7} '  mac.txt  |awk -F =  ' {print $2} '  |awk -f \ '   ' {print $2} ') read -p   "PLEASE INPUT IP:"  IPread -p  "Please input gateway:"  gateread  -p  "Please input prefix:"  precd /etc/sysconfig/network-scriptsif [ -e  ifcfg-eth0 ];&nbsP;thengrep -v ^ipaddr ifcfg-eth0  |grep -v ^onboot|grep -v ^name  |grep -v ^device |grep -v ^prefix |grep -v ^gateway |grep  -v ^hwaddr > /root/ifcfg.txtelsegrep -v ^ipaddr ifcfg-eth1  | grep -v ^onboot|grep -v ^name |grep -v ^device |grep -v ^ Prefix |grep -v ^gateway |grep -v ^hwaddr > /root/ifcfg.txtfised  -i  ' 3a\gateway= ' $GATE '     /root/ifcfg.txtsed -i  ' 3a\prefix= ' $PRE '     /root/ifcfg.txtsed -i  ' 3a\ipaddr= ' $IP '      /root/ ifcfg.txtsed -i  ' 1a\device= ' $ethnumber '      /root/ifcfg.txtsed -i   ' 1a\onboot=yes '      /root/ifcfg.txthwaddr=$ (awk  ' {print $4} '  / root/mac.txt |awk -f ==  ' {print $2} '  |awk -f \ "  ' {print $2} ') sed -i  ' 3a\HWADDR = ' $HWADDR '     /root/ifcfg.txtcp ifcfg-$ethnumber  ifcfg-$ethnumber. bakcp / root/ifcfg.txt  ifcfg-$ethnumberecho   "restart the networking... " service  network restart&&echo  "Modify is scuefull" | | echo  "Modify is failed"

This article is from "Nothing Left" blog, please be sure to keep this source http://3357278.blog.51cto.com/3347278/1627689

VMware VSphere modifies MAC address scripts after creating virtual machines from Templates

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.