声明
作者:昨夜星辰
博客:http://yestreenstars.blog.51cto.com/
本文由本人创作,如需转载,请注明出处,谢谢合作!
目的
在Linux上安装并配置PPTP客户端。
脚本
#!/bin/bash
# 脚本作用:交互式自动安装PPTP客户端
# 作者:昨夜星辰
# 创建时间:2015-04-29
# 修改时间:2015-04-29
echo ‘请输入VPN服务器的相关信息:‘
echo ‘(温馨提示:在输入过程中,如果不小心输错了,那么只能通过Ctrl-C终止脚本重新来过了。)‘
while read -p ‘IP:‘ IP
do
if [ -n "$IP" ]
then
break
fi
done
while read -p ‘用户名:‘ username
do
if [ -n "$username" ]
then
break
fi
done
while read -p ‘密码:‘ password
do
if [ -n "$password" ]
then
break
fi
done
echo ‘信息收集完毕!开始安装并配置PPTP客户端!‘
echo -n ‘正在安装主要软件...‘
(
yum -y install ppp pptp pptp-setup
cp /usr/share/doc/ppp*/scripts/po{n,ff} /usr/sbin/
chmod u+x /usr/sbin/po{n,ff}
) &> /dev/null && echo ‘完成‘ || exit
echo -n ‘正在配置PPTP...‘
(
pptpsetup --create vpn --server $IP --username $username --password $password --encrypt
cat > /etc/ppp/options << EOF
# Lock the port
lock
# We don‘t need the tunnel server to authenticate itself
noauth
# Turn off compression protocols we know won‘t be used
nobsdcomp
nodeflate
# We won‘t do PAP, EAP, CHAP, or MSCHAP, but we will accept MSCHAP-V2
# (you may need to remove these refusals if the server is not using MPPE)
refuse-pap
refuse-eap
refuse-chap
refuse-mschap
EOF
echo ‘#!/bin/bash
# chkconfig: 2345 10 90
prog="vpn"
start() {
if pgrep pppd &> /dev/null
then
echo "The $prog service has been started."
else
echo -n "Starting $prog..."
pon vpn
#sleep 5
#route add -net 0.0.0.0 dev ppp0
while true
do
route add -net 0.0.0.0 dev ppp0 &> /dev/null
if [ "$?" -eq 0 ]
then
break
fi
sleep 1
done
echo "OK"
fi
}
stop() {
if pgrep pppd &> /dev/null
then
echo -n "Stopping $prog..."
poff vpn
echo "OK"
else
echo "The $prog service is not started."
fi
}
status() {
if pgrep pppd &> /dev/null
then
echo "The $prog service is running..."
else
echo "The $prog service is not running..."
fi
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
sleep 1
start
;;
status)
status
;;
*)
echo "Usage: $0 {start|stop|restart|status}"
esac‘ > /etc/init.d/vpn
chmod u+x /etc/init.d/vpn
) &> /dev/null && echo ‘完成‘ || exit
while read -p ‘是否设置VPN为开机自动启动?(y/n)‘ answer
do
case "$answer" in
y)
chkconfig --add vpn
break
;;
n)
break
;;
*)
esac
done
echo ‘安装并配置完毕!有关vpn客户端的启动、停止等操作请参考以下提示:‘
/etc/init.d/vpn参考内容:https://wiki.archlinux.org/index.php/PPTP_VPN_client_setup_with_pptpclient
本文出自 “昨夜星辰” 博客,请务必保留此出处http://yestreenstars.blog.51cto.com/1836303/1640555
原文地址:http://yestreenstars.blog.51cto.com/1836303/1640555