diff --git a/Readme.md b/Readme.md new file mode 100644 index 0000000..c6823de --- /dev/null +++ b/Readme.md @@ -0,0 +1,26 @@ +## Across the Great Wall +## We can reach every corner in the world + +------ + +**pptp.sh** + +> Description: Auto Install PPTP for CentOS 6 +> +> Intro: http://teddysun.com/134.html + +**l2tp.sh** + +> Description: Auto install L2TP for CentOS 6 +> +> Intro: http://teddysun.com/135.html + +**l2tp_ubuntu.sh** + +> Description: Auto install L2TP for Ubuntu +> +> Intro: http://teddysun.com/135.html + + +Copyright 2015 Teddysun + diff --git a/l2tp.sh b/l2tp.sh new file mode 100644 index 0000000..e6fbc7c --- /dev/null +++ b/l2tp.sh @@ -0,0 +1,257 @@ +#!/bin/bash +PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin +export PATH +#=============================================================================================== +# SYSTEM REQUIRED: CentOS 6 (32bit/64bit) +# DESCRIPTION: Auto install L2TP for CentOS 6 +# Author: Teddysun +#=============================================================================================== + +if [[ "$USER" != 'root' ]]; then + echo "Sorry, you need to run this as root" + exit 1 +fi + +if [[ ! -e /dev/net/tun ]]; then + echo "TUN/TAP is not available" + exit 1 +fi + +clear +echo "" +echo "#############################################################" +echo "# Auto install L2TP for CentOS 6 #" +echo "# System Required: CentOS 6(32bit/64bit) #" +echo "# Intro: http://teddysun.com/135.html #" +echo "# #" +echo "# Author: Teddysun #" +echo "# #" +echo "#############################################################" +echo "" + +tmpip=`ifconfig |grep 'inet' | grep -Evi '(inet6|127.0.0.1)' | awk '{print $2}' | cut -d: -f2 | tail -1` +if [[ "$tmpip" = "" ]]; then + tmpip=$(curl -4 icanhazip.com) +fi + +echo "Please input IP-Range:" +read -p "(Default Range: 10.1.2):" iprange +if [ "$iprange" = "" ]; then + iprange="10.1.2" +fi + +echo "Please input PSK:" +read -p "(Default PSK: vpn):" mypsk +if [ "$mypsk" = "" ]; then + mypsk="vpn" +fi + +clear +get_char(){ +SAVEDSTTY=`stty -g` +stty -echo +stty cbreak +dd if=/dev/tty bs=1 count=1 2> /dev/null +stty -raw +stty echo +stty $SAVEDSTTY +} +echo "" +echo "ServerIP:" +echo "$tmpip" +echo "" +echo "Server Local IP:" +echo "$iprange.1" +echo "" +echo "Client Remote IP Range:" +echo "$iprange.2-$iprange.254" +echo "" +echo "PSK:" +echo "$mypsk" +echo "" +echo "Press any key to start...or Press Ctrl+c to cancel" +char=`get_char` +clear + +mknod /dev/random c 1 9 +# Install some necessary tools +yum install -y ppp iptables make gcc gmp-devel xmlto bison flex libpcap-devel lsof vim-enhanced +# +cur_dir=`pwd` +mkdir -p $cur_dir/l2tp +cd $cur_dir/l2tp +# Download openswan-2.6.38.tar.gz +if [ -s openswan-2.6.38.tar.gz ]; then + echo "openswan-2.6.38.tar.gz [found]" +else + echo "openswan-2.6.38.tar.gz not found!!!download now......" + if ! wget http://lamp.teddysun.com/files/openswan-2.6.38.tar.gz;then + echo "Failed to download openswan-2.6.38.tar.gz, please download it to $cur_dir directory manually and retry." + exit 1 + fi +fi +# Download rp-l2tp-0.4.tar.gz +if [ -s rp-l2tp-0.4.tar.gz ]; then + echo "rp-l2tp-0.4.tar.gz [found]" +else + echo "rp-l2tp-0.4.tar.gz not found!!!download now......" + if ! wget http://lamp.teddysun.com/files/rp-l2tp-0.4.tar.gz;then + echo "Failed to download rp-l2tp-0.4.tar.gz, please download it to $cur_dir directory manually and retry." + exit 1 + fi +fi +# Download xl2tpd-1.2.4.tar.gz +if [ -s xl2tpd-1.2.4.tar.gz ]; then + echo "xl2tpd-1.2.4.tar.gz [found]" +else + echo "xl2tpd-1.2.4.tar.gz not found!!!download now......" + if ! wget http://lamp.teddysun.com/files/xl2tpd-1.2.4.tar.gz;then + echo "Failed to download xl2tpd-1.2.4.tar.gz, please download it to $cur_dir directory manually and retry." + exit 1 + fi +fi + +# untar all files +rm -rf $cur_dir/l2tp/untar +mkdir -p $cur_dir/l2tp/untar +echo "======untar all files,please wait a moment=====" +tar -zxf openswan-2.6.38.tar.gz -C $cur_dir/l2tp/untar +tar -zxf rp-l2tp-0.4.tar.gz -C $cur_dir/l2tp/untar +tar -zxf xl2tpd-1.2.4.tar.gz -C $cur_dir/l2tp/untar +echo "=====untar all files completed!=====" +# Install openswan-2.6.38 +cd $cur_dir/l2tp/untar/openswan-2.6.38 +make programs install + +# Configuation ipsec +rm -rf /etc/ipsec.conf +touch /etc/ipsec.conf +cat >>/etc/ipsec.conf<>/etc/ipsec.secrets< $each/accept_redirects +echo 0 > $each/send_redirects +done + +# Install rp-l2tp-0.4 +cd $cur_dir/l2tp/untar/rp-l2tp-0.4 +./configure +make +cp handlers/l2tp-control /usr/local/sbin/ +mkdir -p /var/run/xl2tpd/ +ln -s /usr/local/sbin/l2tp-control /var/run/xl2tpd/l2tp-control +# Install xl2tpd-1.2.4.tar.gz +cd $cur_dir/l2tp/untar/xl2tpd-1.2.4 +make install +mkdir -p /etc/xl2tpd +rm -rf /etc/xl2tpd/xl2tpd.conf +touch /etc/xl2tpd/xl2tpd.conf +cat >>/etc/xl2tpd/xl2tpd.conf<>/etc/ppp/options.xl2tpd<> /etc/ppp/chap-secrets + +touch /usr/bin/l2tpset +echo "#/bin/bash" >>/usr/bin/l2tpset +echo "for each in /proc/sys/net/ipv4/conf/*" >>/usr/bin/l2tpset +echo "do" >>/usr/bin/l2tpset +echo "echo 0 > \$each/accept_redirects" >>/usr/bin/l2tpset +echo "echo 0 > \$each/send_redirects" >>/usr/bin/l2tpset +echo "done" >>/usr/bin/l2tpset +chmod +x /usr/bin/l2tpset +iptables --table nat --append POSTROUTING --jump MASQUERADE +l2tpset +xl2tpd +cat >>/etc/rc.local< # +# # +############################################################# +if there are no [FAILED] above, then you can connect to your +L2TP VPN Server with the default user/password below: + +ServerIP:$tmpip +username:vpn +password:${pass} +PSK:$mypsk +" +exit 0 diff --git a/l2tp_ubuntu.sh b/l2tp_ubuntu.sh new file mode 100644 index 0000000..15753b8 --- /dev/null +++ b/l2tp_ubuntu.sh @@ -0,0 +1,256 @@ +#!/bin/bash +PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin +export PATH +#=============================================================================================== +# SYSTEM REQUIRED: Ubuntu (32bit/64bit) +# DESCRIPTION: Auto install L2TP for Ubuntu +# Author: Teddysun +#=============================================================================================== + +if [[ "$USER" != 'root' ]]; then + echo "Sorry, you need to run this as root" + exit 1 +fi + +if [[ ! -e /dev/net/tun ]]; then + echo "TUN/TAP is not available" + exit 1 +fi + +clear +echo "" +echo "#############################################################" +echo "# Auto install L2TP for Ubuntu #" +echo "# System Required: Ubuntu(32bit/64bit) #" +echo "# Intro: http://teddysun.com/135.html #" +echo "# #" +echo "# Author: Teddysun #" +echo "# #" +echo "#############################################################" +echo "" + +tmpip=`ifconfig |grep 'inet' | grep -Evi '(inet6|127.0.0.1)' | awk '{print $2}' | cut -d: -f2 | tail -1` +if [[ "$tmpip" = "" ]]; then + tmpip=$(curl -4 icanhazip.com) +fi + +echo "Please input IP-Range:" +read -p "(Default Range: 10.1.2):" iprange +if [ "$iprange" = "" ]; then + iprange="10.1.2" +fi + +echo "Please input PSK:" +read -p "(Default PSK: vpn):" mypsk +if [ "$mypsk" = "" ]; then + mypsk="vpn" +fi + +clear +get_char(){ +SAVEDSTTY=`stty -g` +stty -echo +stty cbreak +dd if=/dev/tty bs=1 count=1 2> /dev/null +stty -raw +stty echo +stty $SAVEDSTTY +} +echo "" +echo "ServerIP:" +echo "$tmpip" +echo "" +echo "Server Local IP:" +echo "$iprange.1" +echo "" +echo "Client Remote IP Range:" +echo "$iprange.2-$iprange.254" +echo "" +echo "PSK:" +echo "$mypsk" +echo "" +echo "Press any key to start...or Press Ctrl+c to cancel" +char=`get_char` +clear + +# Install some necessary tools +apt-get install -y ppp iptables make gcc gmp-devel libgmp3-dev bison flex libpcap-devel lsof vim +# +cur_dir=`pwd` +mkdir -p $cur_dir/l2tp +cd $cur_dir/l2tp +# Download openswan-2.6.38.tar.gz +if [ -s openswan-2.6.38.tar.gz ]; then + echo "openswan-2.6.38.tar.gz [found]" +else + echo "openswan-2.6.38.tar.gz not found!!!download now......" + if ! wget http://lamp.teddysun.com/files/openswan-2.6.38.tar.gz;then + echo "Failed to download openswan-2.6.38.tar.gz, please download it to $cur_dir directory manually and retry." + exit 1 + fi +fi +# Download rp-l2tp-0.4.tar.gz +if [ -s rp-l2tp-0.4.tar.gz ]; then + echo "rp-l2tp-0.4.tar.gz [found]" +else + echo "rp-l2tp-0.4.tar.gz not found!!!download now......" + if ! wget http://lamp.teddysun.com/files/rp-l2tp-0.4.tar.gz;then + echo "Failed to download rp-l2tp-0.4.tar.gz, please download it to $cur_dir directory manually and retry." + exit 1 + fi +fi +# Download xl2tpd-1.2.4.tar.gz +if [ -s xl2tpd-1.2.4.tar.gz ]; then + echo "xl2tpd-1.2.4.tar.gz [found]" +else + echo "xl2tpd-1.2.4.tar.gz not found!!!download now......" + if ! wget http://lamp.teddysun.com/files/xl2tpd-1.2.4.tar.gz;then + echo "Failed to download xl2tpd-1.2.4.tar.gz, please download it to $cur_dir directory manually and retry." + exit 1 + fi +fi + +# untar all files +rm -rf $cur_dir/l2tp/untar +mkdir -p $cur_dir/l2tp/untar +echo "======untar all files,please wait a moment=====" +tar -zxf openswan-2.6.38.tar.gz -C $cur_dir/l2tp/untar +tar -zxf rp-l2tp-0.4.tar.gz -C $cur_dir/l2tp/untar +tar -zxf xl2tpd-1.2.4.tar.gz -C $cur_dir/l2tp/untar +echo "=====untar all files completed!=====" +# Install openswan-2.6.38 +cd $cur_dir/l2tp/untar/openswan-2.6.38 +make programs install + +# Configuation ipsec +rm -rf /etc/ipsec.conf +touch /etc/ipsec.conf +cat >>/etc/ipsec.conf<>/etc/ipsec.secrets< $each/accept_redirects +echo 0 > $each/send_redirects +done + +# Install rp-l2tp-0.4 +cd $cur_dir/l2tp/untar/rp-l2tp-0.4 +./configure +make +cp handlers/l2tp-control /usr/local/sbin/ +mkdir -p /var/run/xl2tpd/ +ln -s /usr/local/sbin/l2tp-control /var/run/xl2tpd/l2tp-control +# Install xl2tpd-1.2.4.tar.gz +cd $cur_dir/l2tp/untar/xl2tpd-1.2.4 +make install +mkdir -p /etc/xl2tpd +rm -rf /etc/xl2tpd/xl2tpd.conf +touch /etc/xl2tpd/xl2tpd.conf +cat >>/etc/xl2tpd/xl2tpd.conf<>/etc/ppp/options.xl2tpd<> /etc/ppp/chap-secrets + +touch /usr/bin/l2tpset +echo "#/bin/bash" >>/usr/bin/l2tpset +echo "for each in /proc/sys/net/ipv4/conf/*" >>/usr/bin/l2tpset +echo "do" >>/usr/bin/l2tpset +echo "echo 0 > \$each/accept_redirects" >>/usr/bin/l2tpset +echo "echo 0 > \$each/send_redirects" >>/usr/bin/l2tpset +echo "done" >>/usr/bin/l2tpset +chmod +x /usr/bin/l2tpset +iptables --table nat --append POSTROUTING --jump MASQUERADE +l2tpset +xl2tpd +cat >>/etc/rc.local< # +# # +############################################################# +if there are no [FAILED] above, then you can connect to your +L2TP VPN Server with the default user/password below: + +ServerIP:$tmpip +username:vpn +password:${pass} +PSK:$mypsk +" +exit 0 diff --git a/pptp.sh b/pptp.sh new file mode 100644 index 0000000..28d5847 --- /dev/null +++ b/pptp.sh @@ -0,0 +1,86 @@ +#!/bin/bash +PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin +export PATH +#=================================================================== +# SYSTEM REQUIRED: CentOS 6 (32bit/64bit) +# DESCRIPTION: Auto install pptpd for CentOS 6 +# Author: Teddysun +#=================================================================== + +if [[ "$USER" != 'root' ]]; then + echo "Sorry, you need to run this as root" + exit 1 +fi + +if [[ ! -e /dev/net/tun ]]; then + echo "TUN/TAP is not available" + exit 1 +fi + +cur_dir=`pwd` +clear +echo "" +echo "#############################################################" +echo "# Auto Install PPTP for CentOS 6" +echo "# System Required: CentOS 6(32bit/64bit)" +echo "# Intro: http://teddysun.com/134.html" +echo "" +echo "# Author: Teddysun " +echo "" +echo "#############################################################" +echo "" + +# Remove installed pptpd & ppp +yum remove -y pptpd ppp +iptables --flush POSTROUTING --table nat +iptables --flush FORWARD +rm -f /etc/pptpd.conf +rm -rf /etc/ppp +arch=`uname -m` + +# Download pptpd +if [ -s pptpd-1.3.4-2.el6.$arch.rpm ]; then + echo "pptpd-1.3.4-2.el6.$arch.rpm [found]" +else + echo "pptpd-1.3.4-2.el6.$arch.rpm not found!!!download now......" + if ! wget http://lamp.teddysun.com/files/pptpd-1.3.4-2.el6.$arch.rpm;then + echo "Failed to download pptpd-1.3.4-2.el6.$arch.rpm,please download it to $cur_dir directory manually and rerun the install script." + exit 1 + fi +fi + +# Install some necessary tools +yum -y install net-tools make libpcap iptables gcc-c++ logrotate tar cpio perl pam tcp_wrappers dkms ppp +rpm -ivh pptpd-1.3.4-2.el6.$arch.rpm + +rm -f /dev/ppp +mknod /dev/ppp c 108 0 +echo 1 > /proc/sys/net/ipv4/ip_forward +echo "mknod /dev/ppp c 108 0" >> /etc/rc.local +echo "echo 1 > /proc/sys/net/ipv4/ip_forward" >> /etc/rc.local +echo "localip 192.168.8.1" >> /etc/pptpd.conf +echo "remoteip 192.168.8.2-254" >> /etc/pptpd.conf +echo "ms-dns 8.8.8.8" >> /etc/ppp/options.pptpd +echo "ms-dns 8.8.4.4" >> /etc/ppp/options.pptpd + +pass=`openssl rand 6 -base64` +if [ "$1" != "" ] + then pass=$1 +fi + +echo "vpn pptpd ${pass} *" >> /etc/ppp/chap-secrets + +iptables -t nat -A POSTROUTING -s 192.168.8.0/24 -j SNAT --to-source `ifconfig | grep 'inet addr:'| grep -v '127.0.0.1' | cut -d: -f2 | awk 'NR==1 { print $1}'` +iptables -A FORWARD -p tcp --syn -s 192.168.8.0/24 -j TCPMSS --set-mss 1356 +service iptables save +chkconfig --add pptpd +chkconfig pptpd on +service iptables restart +service pptpd start + +echo "" +echo "VPN service is installed, your VPN username is vpn, VPN password is ${pass}" +echo "Welcome to visit: http://teddysun.com" +echo "" + +exit 0