modify.sh
1.23 KB
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
#!/bin/bash
if [[ $# == 3 ]]
then
type=inner
ip=$1
netmask=$2
whether_reboot=$3
elif [[ $# == 4 ]]
then
type=out
ip=$1
netmask=$2
gateway=$3
whether_reboot=$4
else
echo Modify IP ERROR!
exit 0
fi
if [[ $type == inner ]]
then
net=`egrep -o '^auto eth0$' /etc/network/interfaces`
if [[ $net ]]
then
sed -i /"^auto eth0$"/,/"^address.*$"/s/"address.*$"/"address $ip"/ /etc/network/interfaces
sed -i /"^auto eth0$"/,/"^netmask.*$"/s/"^netmask.*$"/"netmask $netmask"/ /etc/network/interfaces
sed -i /"^auto eth0$"/,/"^auto eth1"/s/"^gateway"/"#gateway"/ /etc/network/interfaces
fi
elif [[ $type == out ]]
then
net=`egrep -o '^auto eth1$' /etc/network/interfaces`
if [[ $net ]]
then
sed -i /"^auto eth1$"/,/"^address.*$"/s/"address.*$"/"address $ip"/ /etc/network/interfaces
sed -i /"^auto eth1$"/,/"^netmask.*$"/s/"^netmask.*$"/"netmask $netmask"/ /etc/network/interfaces
sed -i /"^auto eth1$"/,/"^gateway.*$"/s/"^gateway.*$"/"gateway $gateway"/ /etc/network/interfaces
fi
fi
if [[ $whether_reboot = reboot ]]
then
reboot_time=`date -d "1 minutes" +%H:%M`
echo "IP($ip)修改成功,系统将会在$reboot_time重启"
shutdown -r $reboot_time
else
echo "IP($ip)修改成功, 请在合适的时间重启系统(reboot -f)"
fi