克隆之后一键修改IP、删除Mac地址、修改主机名(未测试成功只是思路)

克隆之后需要修改IP、删除Mac地址、修改主机名
1.IP
因为IP存在于/etc/sysconfig/network-scripts/ifcfg-eth0
使用sed -i “linec”替换IP--line实际写具体数字
如果存在HWADDR,将删除HWADDR

2.删除Mac地址
rm -rf /etc/udev/rules.d/70-persistent-net.rules
3.永久修改主机名
vi  /etc/sysconfig/network
将里面的HOSTNAME修改
4.重启网卡
service network restart
5.重启服务器
reboot

--------------------------------------------

ai-copylinux.sh

#!/bin/sh
#克隆之后一键修改IP、删除Mac地址、修改主机名

#定义常量,便于引用
HOST_NAME='/etc/sysconfig/network'
HOSTNAME='hostname'
ETH0='/etc/sysconfig/network-scripts/ifcfg-eth0'
RULES='/etc/udev/rules.d/70-persistent-net.rules'

#删除Mac地址
rm -rf ${RULES}
echo "${RULES}已删除成功"

#修改IP地址、删除Mac地址
read -p "是否修改ifcfg-eth0文件(y/n): " yn
if [ "$yn" == "Y" ] || [ "$yn" == "y" ];then
#修改IP地址
read -p "输入IP地址:" IP
sed -i "8c IPADDER=${IP}" ${ETH0}
read -p "输入GATEWAY地址:" GATE
sed -i "9c GATEWAY=${GATE}" ${ETH0}
#删除Mac
sed -i "2d" ${ETH0}
#重启网卡
service network restart
cat ${ETH0}
fi

#修改主机名
read -p "当前主机名为${HOSTNAME},是否修改(y/n): " yn
if [ "$yn" == "Y" ] || [ "$yn" == "y" ];then
   read -p "请输入主机名:" hdp
   sed -i "2c HOSTNAMT=${hdp}" ${HOST_NAME}
fi

read -p "主机名修改完成,重启系统使之生效,是否重启系统(y/n):" yn
if [ "$yn" == "Y" ] || [ "$yn" == "y" ];then
  echo "即将重启系统..."
  reboot
elif [ "$yn" == "n" ] || [ "$yn" == "N" ];then
  echo "主机名修改后需要重启系统使之生效,请手动重启系统..."
fi
elif [ "$yn" == "n" ] || [ "$yn" = "N" ];then
  echo "主机名没有修改!"
fi
---------------
copy正常的linux时:2d、8c、9c
copy的是克隆的linux:
因为没有2.HWADDR,就不用删除2d
替换是改为7c-替换IPADDR,8c--替换GATEWAY
 

posted @ 2018-09-30 16:06  IT晓白  阅读(711)  评论(0编辑  收藏  举报