1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
#!/bin/bash #2017-7-13 #by ip_file= /etc/sysconfig/network-scripts/ifcfg-eth0
zt=` grep "static" $ip_file| wc -l`
Bf_file= /data/ifcfg-eth/ ` date "+%y_%m_%d" `/
IPADDR= "192.168.25.107"
netmask= "255.255.255.0"
getaway= "192.168.25.2"
#备份原来的配置文件 #Back up the original configuration file if [ ! -d $Bf_file ]; then
mkdir -p $Bf_file
fi cp $ip_file $Bf_file
#修改IP #change ip if [ $zt - eq 1 ]; then
sed -i s #IPADDR.*#IPADDR=$IPADDR#g $ip_file
sed -i s #NETMASK.*#NETMASK=$netmask#g $ip_file
sed -i s #GATEWAY.*#GATEWAY=$getaway#g $ip_file
else sed -i s #BOOTPROTO.*#BOOTPROTO=static#g $ip_file
cat >>$ip_file<< EOF
IPADDR=$IPADDR NETMASK=$netmask GATEWAY=$getaway EOF fi #重启服务并打印配置文件 #Restart the service and print the configuration file sleep 2
service network restart echo "_________________________________"
cat $ip_file
echo "_________________________________"
ifconfig echo "________________________________"
ifconfig eth0
|
本文转自 天道酬勤VIP 51CTO博客,原文链接:http://blog.51cto.com/tdcqvip/1947248