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"
相關文章
相關標籤/搜索