Linux服务器IP修改脚本 ;
配置Linux服务器静态I地址P。
IP配置默认存放路径:/etc/sysconfig/network-scripts/。
修改IP地址会同步修改:IP、NETMASK、GATEWAY。
IP地址修改完成后,确认重启网卡服务。
vim automatically_modify_server_IP.sh
#!/bin/bash
#2021-3-22 10:41:02
#auto change server ip
#Automatically modify server IP
######################
ETH_DEV="ens33"
BAK_DIR="/data/backup/`date +%Y%m%d`"
NETMASK="255.255.255.0"
GATEWAY="192.168.11.1"
DNS1="114.114.114.114
ETH_DIR="/etc/sysconfig/network-scripts/"
read -p "Please Enter Server IP address; " IPADDR
mkdir -p $BAK_DIR/
cd $ETH_DIR
cp ifcfg-${ETH_DEV} $BAK_DIR/ifcfg-${ETH_DEV}.$$
echo "TYPE=Ethernet
BOOTPROTO=static
ONBOOT=yes
DEVICE=$ETH_DEV
IPADDR=$IPADDR
NETMASK=$NETMASK
GATEWAY=$GATEWAY
DNS1=$DNS1">ifcfg-${ETH_DEV}
echo -e "\033[32m------------------------------\033[0m"
cat ifcfg-${ETH_DEV}
echo
sleep 2
#read -p "Plesae Enter yes or on,Restart Network.service or Quit?:" INPUT
read -p "Network Service is about to restart,To confirm enter either YES or ON?:" INPUT
if [ $INPUT == "yes" -o $INPUT == "y" -o $INPUT == "yes" -o $INPUT == "Y" ];then
service network restart
elif [ $INPUT == "R" -o $INPUT == "r" ];then
\cp $BAK_DIR/ifcfg-${ETH_DEV}.$$ ifcfg-${ETH_DEV}
cat ifcfg-${ETH_DEV}
fi