#!/bin/bash# automatic with ip # author: tianzhaogao (e-mail: [email protected]) line_ num=$ (cat /etc/sysconfig/network-scripts/ifcfg-eth0 | wc -l) while [ "$line _num" -gt 7 ]dosed -i ' 8c \ ' /etc/sysconfig/network-scripts/ifcfg-eth0line_num=$ (cat /etc/sysconfig/network-scripts/ifcfg-eth0 | wc -l) Doneread -t 30 -p "PLEASE INPUT IP:" ipnumn1=$ (echo "$ipnum" | cut -d "." -f 1) n2=$ (echo "$ipnum" | cut -d "."  -F 2) n3=$ (echo "$ipnum" | cut -d "." -f 3) n4=$ (echo "$ipnum" | cut -d "." -f 4) if [ "$n 1" -le 255 -a "$n 2" -le 255 -a "$n 3" -le 255 -a "$n 4" -le 255 ];thenecho -e ipaddr= "$ipnum" \ n " netmask=255.255.255.0 "\ n" getway= "$n1 "\." $n 2 "\." $n 3 "\.1" \ n "ipv6init=no" \ n "userctl=no >> /etc/sysconfig/network-scripts/ifcfg-eth0sed -i ' s/onboot= ' no '/onboot= ' yes '/g ' /etc/sysconfig/network-scripts/ifcfg-eth0sed -i ' s/ Bootproto=dhcp/bootproto=none/g ' /etc/sysconfig/network-scripts/ifcfg-eth0sed -i ' s/onboot=no/ Onboot=yes/g ' /etc/sysconfig/network-scripts/ifcfg-eth0service network restartfi
This article is from the "mild feeling Blue Sky" blog, please make sure to keep this source http://tianzhaogao.blog.51cto.com/4716906/1693194
Simple script for Linux beginners----automatically with IP