Linux System Brush Station group IP script

Source: Internet
Author: User

The station group server has many IP addresses, and if configured manually, it takes a lot of time. Using shell scripts to automate configuration can effectively improve productivity. As follows:

    1. First configure the server first IP, and then SSH login to the server;

    2. Create the file Iprange.txt under/root and write the IP segment to Iprange.txt, as follows

      #cat Iprange.txt

      192.168.10.0/28

      192.168.10.16/28

      192.168.20.32/28

      ........

    3. Create a script

#vi iprange.sh

#!/bash/bash

Read-p "Please enter Ip_range ' TXT document:" Iprange.txt

Path=/etc/sysconfig/network-scripts

N=0

S=0

For i in '/bin/cat/root/iprange.txt '

Do

id=${i#*/} #截取后缀

add=${i%.*} #截取网段

prefix=${i%/*}

host=${prefix##*.} #截取第4个字段

If [$ID-eq]; then

Start= '/usr/bin/expr $HOST + 2 '

End= '/usr/bin/expr $START + 12 '

m=240

If [$N-eq 0]; Then

S=0

Else

Let s+= '/usr/bin/expr $END-$START + 1 '

Fi

Fi

If [$ID-eq]; then

Start= '/usr/bin/expr $HOST + 2 '

End= '/usr/bin/expr $START + 252 '

M=0

If [$N-eq 0]; Then

S=0

Else

Let s+= '/usr/bin/expr $END-$START + 1 '

Fi

Fi

If [$ID-eq]; then

Start= '/usr/bin/expr $HOST + 2 '

End= '/usr/bin/expr $START + 124 '

m=128

If [$N-eq 0]; Then

S=0

Else

Let s+= '/usr/bin/expr $END-$START + 1 '

Fi

Fi

If [$ID-eq]; then

Start= '/usr/bin/expr $HOST + 2 '

End= '/usr/bin/expr $START + 60 '

m=192

If [$N-eq 0]; Then

S=0

Else

Let s+= '/usr/bin/expr $END-$START + 1 '

Fi

Fi

If [$ID-eq]; then

Start= '/usr/bin/expr $HOST + 2 '

End= '/usr/bin/expr $START + 28 '

m=224

If [$N-eq 0]; Then

S=0

Else

Let s+= '/usr/bin/expr $END-$START + 1 '

Fi

Fi

If [$ID-eq]; then

Start= '/usr/bin/expr $HOST + 2 '

End= '/usr/bin/expr $START + 4 '

m=248

If [$N-eq 0]; Then

S=0

Else

Let s+= '/usr/bin/expr $END-$START + 1 '

Fi

Fi

Echo-n-E "Device=eth$j\nonboot=yes\nbootproto=static\nipaddr_start=${add}. $START \nipaddr_end=${add}. $END \ nclonenum_start= $S \nnetmask=255.255.255 $M "> $PATH/ifcfg-eth0-range$n

Let n++

Done


4. Execute the Script

#sh iprange.sh


5. Restart the NIC and check if the configuration is successful

#service Network Restart

#ifconfig


6. Deleting a script


Complete!

This article from "Dave-Technology blog" blog, declined reprint!

Linux System Brush Station group IP script

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.