一个简单修改服务器网络配置的脚本


#!/bin/sh

eth0=/etc/sysconfig/network-scripts/ifcfg-enp0s3
mac=`ifconfig -a | grep -o HWaddr.* | cut -c 8-24`

echo "$1"
echo "$2"
echo "$3"
echo "$4"
echo "$5"

if [ "$1" = "" ] || [ "$2" = "" ]; then echo 'exit'; exit 3; fi

sed -i 's/IPADDR0=.*/IPADDR0=192.168.'$1'.'$2'/g' $eth0

if [ "$mac" != "" ]; then
sed -i 's/HWADDR=.*/HWADDR='$mac'/g' $eth0
else
echo 'mac is empty'
fi

if [ "$3" != "" ] && [ "$4" != "" ]; then
sed -i 's/GATEWAY0=.*/GATEWAY0=192.168.'$3'.'$4'/g' $eth0
else
echo 'no update GATEWAY'
fi

if [ "$5" = "update"]; then
sed -i 's/UUID=.*/UUID='`uuidgen`'/g' $eth0
else
echo 'no update UUID'
fi

echo 'over'
service network restart

 

 

执行./netconfig.sh  11 22 0 1即可,11 22为ip后两位,0 1为网关。网关不对,小心连不上外网哦

 

posted @ 2019-08-16 14:24  谦逊的铅笔  阅读(646)  评论(0编辑  收藏  举报