Advertisement
Guest User

Untitled

a guest
Feb 15th, 2016
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.19 KB | None | 0 0
  1. #!/bin/sh
  2. # Setup Simple PPTP VPN server for Ubuntu and Debian
  3. # Copyright (C) 2013-2015 Viljo Viitanen <viljo.viitanen@iki.fi> and contributors
  4. #
  5. # This program is free software; you can redistribute it and/or modify
  6. # it under the terms of the GNU General Public License as published by
  7. # the Free Software Foundation; either version 2 of the License, or
  8. # (at your option) any later version.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License along
  16. # with this program; if not, write to the Free Software Foundation, Inc.,
  17. # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  18. #
  19. # 2013-11-06: initial version. Tested with Amazon EC2 Ubuntu 12.04 and
  20. # Digital Ocean Debian 7.0 and Ubuntu 12.04 images.
  21. # 2014-03-23: Added apt-get update.
  22. # 2014-09-18: Add help, allow custom username and password, thanks to dileep-p
  23. # 2015-01-25: Change external ip provider, thanks to theroyalstudent
  24.  
  25. printhelp() {
  26.  
  27. echo "
  28.  
  29. Usage: sh setup.sh [OPTION]
  30.  
  31. If you are using custom password , Make sure its more than 8 characters. Otherwise it will generate random password for you.
  32.  
  33. If you trying set password only. It will generate Default user with Random password.
  34.  
  35. example: sudo bash setup.sh -u vpn -p mypass
  36.  
  37. Use without parameter [ sudo bash setup.sh ] to use default username and Random password
  38.  
  39.  
  40. -u, --username Enter the Username
  41. -p, --password Enter the Password
  42. "
  43. }
  44.  
  45. while [ "$1" != "" ]; do
  46. case "$1" in
  47. -u | --username ) NAME=$2; shift 2 ;;
  48. -p | --password ) PASS=$2; shift 2 ;;
  49. -h | --help ) echo "$(printhelp)"; exit; shift; break ;;
  50. esac
  51. done
  52.  
  53. if [ `id -u` -ne 0 ]
  54. then
  55. echo "Need root, try with sudo"
  56. exit 0
  57. fi
  58.  
  59.  
  60. rpm -i http://poptop.sourceforge.net/yum/stable/rhel6/pptp-release-current.noarch.rpm
  61. yum -y install pptpd
  62.  
  63.  
  64. #ubuntu has exit 0 at the end of the file.
  65. sed -i '/^exit 0/d' /etc/rc.local
  66.  
  67. cat >> /etc/rc.local << END
  68. echo 1 > /proc/sys/net/ipv4/ip_forward
  69. #control channel
  70. iptables -I INPUT -p tcp --dport 1723 -j ACCEPT
  71. #gre tunnel protocol
  72. iptables -I INPUT --protocol 47 -j ACCEPT
  73.  
  74. iptables -t nat -A POSTROUTING -s 192.168.2.0/24 -d 0.0.0.0/0 -o eth0 -j MASQUERADE
  75.  
  76. #supposedly makes the vpn work better
  77. iptables -I FORWARD -s 192.168.2.0/24 -p tcp -m tcp --tcp-flags FIN,SYN,RST,ACK SYN -j TCPMSS --set-mss 1356
  78.  
  79. END
  80. sh /etc/rc.local
  81.  
  82. #no liI10oO chars in password
  83.  
  84. LEN=$(echo ${#PASS})
  85.  
  86. if [ -z "$PASS" ] || [ $LEN -lt 8 ] || [ -z "$NAME"]
  87. then
  88. P1=`cat /dev/urandom | tr -cd abcdefghjkmnpqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ23456789 | head -c 3`
  89. P2=`cat /dev/urandom | tr -cd abcdefghjkmnpqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ23456789 | head -c 3`
  90. P3=`cat /dev/urandom | tr -cd abcdefghjkmnpqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ23456789 | head -c 3`
  91. PASS="$P1-$P2-$P3"
  92. fi
  93.  
  94. if [ -z "$NAME" ]
  95. then
  96. NAME="vpn"
  97. fi
  98.  
  99. cat >/etc/ppp/chap-secrets <<END
  100. # Secrets for authentication using CHAP
  101. # client server secret IP addresses
  102. $NAME pptpd $PASS *
  103. END
  104. cat >/etc/pptpd.conf <<END
  105. option /etc/ppp/options.pptpd
  106. logwtmp
  107. localip 192.168.2.1
  108. remoteip 192.168.2.10-100
  109. END
  110. cat >/etc/ppp/options.pptpd <<END
  111. name pptpd
  112. refuse-pap
  113. refuse-chap
  114. refuse-mschap
  115. require-mschap-v2
  116. require-mppe-128
  117. ms-dns 8.8.8.8
  118. ms-dns 8.8.4.4
  119. proxyarp
  120. lock
  121. nobsdcomp
  122. novj
  123. novjccomp
  124. nologfd
  125. END
  126.  
  127.  
  128. #find out external ip
  129. IP=`wget -q -O - http://api.ipify.org`
  130.  
  131. if [ "x$IP" = "x" ]
  132. then
  133. echo "============================================================"
  134. echo " !!! COULD NOT DETECT SERVER EXTERNAL IP ADDRESS !!!"
  135. else
  136. echo "============================================================"
  137. echo "Detected your server external ip address: $IP"
  138. fi
  139. echo ""
  140. echo "VPN username = $NAME password = $PASS"
  141. echo "============================================================"
  142. sleep 2
  143.  
  144. service pptpd restart
  145.  
  146. exit 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement