Common scripts for work and teaching, updated from time to time

Change the IP and hostname

#!/bin/bash
if [ `whoami` != root ]
then
echo "Please login as root to continue :)"
exit
fi
oip=`grep "IPADDR" /etc/sysconfig/network-scripts/ifcfg-ens33 |awk -F '=' '{print $2}'|cut -d '"' -f2`
while read -p "Pls input your IPADDRESS,Like 10.119.10.10 :" ip
do
read -p "Your NewIP is ${ip},Make Sure[y|n]:" yn
if [[ ${yn} == [Yy] ]];then
sed -i "s/$oip/$ip/g" /etc/sysconfig/network-scripts/ifcfg-ens33
echo "IP: "${ip}
fi
read -p "Pls input your's hostname: " hname
read -p 'Make sure"'${hname}'"is hostname [y|n]:'in 
me
sudo hostnamectl set-hostname $ {hname}
if [[$ {in} == [Yy]]]; then
service network restart
exit
done


Guess you like

Origin blog.51cto.com/jinyan2049/2609067