# grep -v "#" /etc/pptpd.conf
option
/etc/ppp/options
.pptpd
logwtmp
localip 10.1.1.101
#VPN server的起始ip,注意不是VPN server的真实的ip
remoteip 10.1.253.1-254,10.1.0.254
#vpn client分配的ip
/etc/ppp/chap-secrets
# grep -v "#" /etc/ppp/options.pptpd
name pptpd
refuse-pap
refuse-chap
refuse-mschap
require-mschap-v2
require-mppe-128
proxyarp
lock
nobsdcomp
novj
novjccomp
nologfd
ms-dns 8.8.8.8
ms-dns 8.8.4.4
# Secrets for authentication using CHAP
# client server secret IP addresses
user pptpd
passwd
*
service pptpd restart
service pptpd reload
-A FORWARD -m state --state RELATED,ESTABLISHED -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 1723 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 47 -j ACCEPT
-A INPUT -p gre -j ACCEPT
pptpsetup -create idcvpn -server vpn公网ip -username 用户名 -password 密码 -encrypt -start
route add -net 10.1.0.0
/16
dev ppp0
#添加路由,否则不通,因为服务器的网段是10.1.0.0/16
cp
/usr/share/doc/ppp-2
.4.5
/scripts/pon
/usr/sbin/
cp
/usr/share/doc/ppp-2
.4.5
/scripts/poff
/usr/sbin/
chmod
+x
/usr/sbin/pon
/usr/sbin/poff
pon idcvpn
#开启VPN
route add -net 10.1.0.0
/16
dev ppp0
poff idcvpn
#关闭VPN
cat
/etc/sysconfig/iptables
*nat
:PREROUTING ACCEPT [0:0]
:POSTROUTING ACCEPT [1:92]
:OUTPUT ACCEPT [1:92]
-A POSTROUTING -d 10.1.0.0
/16
-o ppp0 -j MASQUERADE
COMMIT
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
COMMIT
#!/bin/bash
# vpn_monitor
# by H2O
# V1.0_2014.07.23
source
/etc/profile
function
JudgeVpn(){
#判断VPN是否存活,为了判断准确定,需要判断多次
FLAG=1
ping
-c 1 10.1.1.1 -w 1 >
/dev/null
2>&1 && FLAG=0
ping
-c 1 10.1.1.2 -w 1 >
/dev/null
2>&1 && FLAG=0
ping
-c 1 10.1.1.103 -w 1>
/dev/null
2>&1 && FLAG=0
return
"$FLAG"
}
function
Run_Vpn(){
Now_Time=`
date
"+%F_%T"
`
echo
"$Now_Time,vpn is not running"
poff idcvpn ||poff idcvpn || poff idcvpn
#可能失败,多尝试几次
pon idcvpn || pon idcvpn || pon idcvpn
#可能失败,多尝试几次
sleep
5
#拨号之后,需要有一定时间才能出现设备ppp0,这里等5s,可以自己实践
route add -net 10.1.0.0
/16
dev ppp0 || route add -net 10.1.0.0
/16
dev ppp0 || route add -net 10.1.0.0
/16
dev ppp0
#路由可能添加失败,多尝试几次
route add -net 10.1.0.0
/16
dev ppp0
echo
"$Now_Time,vpn runned"
}
JudgeVpn
Status=$?
if
[
"$Status"
-
eq
1 ];
then
Run_Vpn
#run vpn 之后,不一定能马上ping通
sleep
5
JudgeVpn
Status=$?
if
[
"$Status"
-
eq
1 ];
then
Run_Vpn
else
Now_Time=`
date
"+%F_%T"
`
echo
"$Now_Time,vpn is running"
exit
0
fi
else
Now_Time=`
date
"+%F_%T"
`
echo
"$Now_Time,vpn is running"
exit
0
fi