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:
First configure the server first IP, and then SSH login to the server;
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
........
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