Ubuntu脚本修改IP信息

#!/bin/bash
cd /etc/network
#清除4-9行
sed -i '4,9d' interfaces
#在第3行添加网卡名称
sed -i "3a auto ${1}" interfaces
#在第4行添加
sed -i "4a iface ${1} inet static" interfaces
#在第5行添加IP
sed -i "5a address ${2}" interfaces
#在第6行添加子网掩码
sed -i "6a netmask ${3}" interfaces
#在第7行添加网关
sed -i "7a gateway ${4}" interfaces
#在第8行添加DNS
if test -z "${5}"
then
  sed -i "8a dns-nameservers 0.0.0.0" interfaces
else 
  sed -i "8a dns-nameservers ${5}" interfaces
fi
echo "chang is succes"

 

posted @ 2018-10-12 09:31  米罗西  阅读(718)  评论(0编辑  收藏  举报