LoginSignup
2
2

More than 5 years have passed since last update.

【自分用】Centos6 VMをコピーした時にudev-rulesとホスト名を書換えるshell

Last updated at Posted at 2015-05-20

概要

VMWare WorkstationとかPlayerを使っている時、
CentOS6のVMをコピーするとeth設定が面倒なことになる。
都度手動は面倒なので、コピー元のVMにshellを置いておくことにする。

以下script

udev_set.sh

#!/bin/sh -x
clear

# input user information
echo "input New Host Name"
read HostName
echo

# confirm input data
echo "HostName:  ${HostName}"
echo

echo "Are You OK?"
read RES
case ${RES} in
   Yes|yes|Y|y )
      break ;;
   No|no|N|n )
      exit ;;
   * )
      echo
      echo
      echo "input Yes or No"
      exit ;;
esac

# change hostname
NAMEDIR=/etc/sysconfig/network

sed -i /^HOSTNAME/d ${NAMEDIR}
sed -i /^$/d ${NAMEDIR}
echo "HOSTNAME=${HostName}" >> ${NAMEDIR}

# set udev-rules
CONF=/etc/udev/rules.d/70-persistent-net.rules

cat /dev/null > ${CONF}

# server reboot
echo
echo "Server Reboot after 5 seconds"
sleep 5
reboot
2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2