bin sh date tmp last-ip-up txt dhcpc_start proc_udhcp ps grep udhcpc g

 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
52
53
54
55
56
57
58
59
60
61
#!/bin/sh
date >> /tmp/last-ip-up.txt
dhcpc_start=0
proc_udhcp=`ps | grep udhcpc | grep -v grep | wc -l`
if [ $proc_udhcp -eq 0 ] ; then
udhcpc -i vlan1 -s dhcpc-event
echo 1 > /tmp/vlan1_ip.txt
dhcpc_start=1
fi
gw=`route | grep default | grep vlan1 | awk '{print $2}'`
route add -host 195.138.80.40 gw $gw dev vlan1
route add -host 195.138.80.50 gw $gw dev vlan1
route add -host 195.138.80.33 gw $gw dev vlan1
route add -host 195.138.80.54 gw $gw dev vlan1
route add -host 195.138.80.52 gw $gw dev vlan1
route add -net 195.138.68.88 netmask 255.255.255.248 gw 10.0.203.250 dev vlan1
route add -net 195.138.78.64 netmask 255.255.255.240 gw $gw dev vlan1
route add -net 192.168.0.0 netmask 255.255.0.0 gw $gw dev vlan1
route add -net 10.0.0.0 netmask 255.0.0.0 gw $gw dev vlan1
route del default vlan1
vlan1_ip=`ifconfig vlan1 | grep addr: | awk '{split($2,ip,":"); print ip[2]}'`
snat=`iptables -t nat -L | grep "10\.0\.0\.0" | grep -v grep | wc -l`
cur_ip=`cat /tmp/vlan1_ip.txt`
if [ $snat -eq 0 ] ; then
iptables -A FORWARD -s 172.16.1.0/24 -j ACCEPT
iptables -A FORWARD -d 172.16.1.0/24 -j ACCEPT
iptables -t nat -A POSTROUTING -o vlan1 -s 172.16.1.0/24 -d 195.138.80.40 -j SNAT --to-source $vlan1_ip
iptables -t nat -A POSTROUTING -o vlan1 -s 172.16.1.0/24 -d 195.138.80.50 -j SNAT --to-source $vlan1_ip
iptables -t nat -A POSTROUTING -o vlan1 -s 172.16.1.0/24 -d 195.138.80.33 -j SNAT --to-source $vlan1_ip
iptables -t nat -A POSTROUTING -o vlan1 -s 172.16.1.0/24 -d 195.138.80.54 -j SNAT --to-source $vlan1_ip
iptables -t nat -A POSTROUTING -o vlan1 -s 172.16.1.0/24 -d 195.138.80.52 -j SNAT --to-source $vlan1_ip
iptables -t nat -A POSTROUTING -o vlan1 -s 172.16.1.0/24 -d 195.138.68.88/29 -j SNAT --to-source $vlan1_ip
iptables -t nat -A POSTROUTING -o vlan1 -s 172.16.1.0/24 -d 195.138.78.64/28 -j SNAT --to-source $vlan1_ip
iptables -t nat -A POSTROUTING -o vlan1 -s 172.16.1.0/24 -d 192.168.0.0/16 -j SNAT --to-source $vlan1_ip
iptables -t nat -A POSTROUTING -o vlan1 -s 172.16.1.0/24 -d 10.0.0.0/8 -j SNAT --to-source $vlan1_ip
iptables -I FORWARD -p tcp -i ppp0 --dport 34004 -j ACCEPT
iptables -A PREROUTING -t nat -p tcp -i ppp0 --dport 34004 -j DNAT --to 172.16.1.99:34004
iptables -I FORWARD -p tcp -i vlan1 --dport 34004 -j ACCEPT
iptables -A PREROUTING -t nat -p tcp -i vlan1 --dport 34004 -j DNAT --to 172.16.1.99:34004
elif [ $cur_ip != $vlan1_ip ] ; then
iptables -t nat -F POSTROUTING
iptables -t nat -A POSTROUTING -o ppp0 -s 172.16.1.0/24 -j MASQUERADE
iptables -t nat -A POSTROUTING -o vlan1 -s 172.16.1.0/24 -d 195.138.80.40 -j SNAT --to-source $vlan1_ip
iptables -t nat -A POSTROUTING -o vlan1 -s 172.16.1.0/24 -d 195.138.80.50 -j SNAT --to-source $vlan1_ip
iptables -t nat -A POSTROUTING -o vlan1 -s 172.16.1.0/24 -d 195.138.80.33 -j SNAT --to-source $vlan1_ip
iptables -t nat -A POSTROUTING -o vlan1 -s 172.16.1.0/24 -d 195.138.80.54 -j SNAT --to-source $vlan1_ip
iptables -t nat -A POSTROUTING -o vlan1 -s 172.16.1.0/24 -d 195.138.80.52 -j SNAT --to-source $vlan1_ip
iptables -t nat -A POSTROUTING -o vlan1 -s 172.16.1.0/24 -d 195.138.68.88/29 -j SNAT --to-source $vlan1_ip
iptables -t nat -A POSTROUTING -o vlan1 -s 172.16.1.0/24 -d 195.138.78.64/28 -j SNAT --to-source $vlan1_ip
iptables -t nat -A POSTROUTING -o vlan1 -s 172.16.1.0/24 -d 192.168.0.0/16 -j SNAT --to-source $vlan1_ip
iptables -t nat -A POSTROUTING -o vlan1 -s 172.16.1.0/24 -d 10.0.0.0/8 -j SNAT --to-source $vlan1_ip
fi
echo $vlan1_ip > /tmp/vlan1_ip.txt
route del default vlan1