码迷,mamicode.com
首页 > 系统相关 > 详细

设置IP地址shell脚本

时间:2018-08-19 16:14:26      阅读:574      评论:0      收藏:0      [点我收藏+]

标签:please   boot   art   ash   gateway   bash   dhcp   pad   sed -n   

#!/bin/bash A="IPADDR.*" B="NETMASK.*" C="GATEWAY.*" D="DNS1.*" E="/etc/sysconfig/network-scripts/ifcfg-eth1" F="cat $E | sed -n ‘/BOOTP/p‘" if [ ! "$F" = "BOOTPROTO=dhcp" ] then read -t 30 -p "Please enter the IP address:" IP read -t 30 -p "Please enter mask:" MASK read -t 30 -p "Please enter gateway:" GW read -t 30 -p "Please enter DNS address:" DNS if [ ! -z "$IP" -a ! -z "$MASK" -a ! -z "$GW" -a ! -z "$DNS" ] then sed -i "s/$A/IPADDR=$IP/" $E sed -i "s/$B/NETMASK=$MASK/" $E sed -i "s/$C/GATEWAY=$GW/" $E sed -i "s/$D/DNS1=$DNS/" $E sed -i ‘s/ONBOOT.*/ONBOOT=yes/‘ $E else echo "Error:The input is invalid!!!!" exit 1 fi echo "Please later....." /etc/init.d/network restart &>/dev/null echo "Network card has been configured successfully" else echo "You are already enabled for DHCP" exit 2 fi

这是一个简单的设置静态IP的shell脚本,和大家分享

设置IP地址shell脚本

标签:please   boot   art   ash   gateway   bash   dhcp   pad   sed -n   

原文地址:http://blog.51cto.com/13929859/2161601

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!