#/bin/bash
echo "###input ip you want change to ### "
ipfront=192.168.2. #我想要改的2网段的,可以根据你的需求更改
read ip1
ip="${ipfront}${ip1}"
echo "###ip====" $ip "###"
eth=`find /etc/sysconfig/network-scripts/ -name "ifcfg-e*" |sort |head -1 |awk -F/ '{print $5}'`
ethfile="/etc/sysconfig/network-scripts/$eth"
echo "${ethfile}"
sed -i 's/BOOTPROTO=dhcp/BOOTPROTO=static/g' "${ethfile}"
sed -i 's/^ONBOOT=no/ONBOOT=yes/g' "${ethfile}"
sed -i 's/IPADDR.*/'IPADDR="${ip}"'/g' "${ethfile}"
sed -i 's/NETMASK.*/NETMASK=24/g' "${ethfile}"
sed -i 's/GATEWAY.*/GATEWAY=192.168.2.2/g' "${ethfile}"
echo "DNS1=8.8.8.8 >>${ethfile}"
systemctl restart network
更改IP地址脚本
最新推荐文章于 2024-07-07 01:58:28 发布