#!/bin/sh # Set VPN user read -p "Please set VPN username (default: vpnuser): " VPN_USER if [ "$VPN_USER" = "" ]; then VPN_USER="vpnuser" fi # Set VPN password read -p "Please set VPN password (default: 123): " VPN_PASSWORD if [ "$VPN_PASSWORD" = "" ]; then VPN_PASSWORD="123" fi # Set VPN IPSEC_PSK read -p "Please set VPN IPSEC_PSK (default: 123): " IPSEC_PSK if [ "$IPSEC_PSK" = "" ]; then IPSEC_PSK="123" fi # Update server # apt-get update && apt-get upgrade -y # VPN 1 - Setup L2TP-IPSEC PRIVATE_IP=`wget -q -O - 'http://169.254.169.254/latest/meta-data/local-ipv4'` PUBLIC_IP=`wget -q -O - 'http://169.254.169.254/latest/meta-data/public-ipv4'` apt-get install -y openswan xl2tpd cat > /etc/ipsec.conf < /etc/ipsec.secrets < /etc/xl2tpd/xl2tpd.conf < /etc/ppp/options.xl2tpd < /etc/ppp/chap-secrets < /proc/sys/net/ipv4/ip_forward iptables-save > /etc/iptables.rules cat > /etc/network/if-pre-up.d/iptablesload < /proc/sys/net/ipv4/ip_forward exit 0 EOF chmod a+x /etc/network/if-pre-up.d/iptablesload /etc/init.d/ipsec restart /etc/init.d/xl2tpd restart #VPN 2 - Setup PPTP Server apt-get install pptpd -y echo "localip 10.0.0.1" >> /etc/pptpd.conf echo "remoteip 10.0.0.100-200" >> /etc/pptpd.conf echo "$VPN_USER pptpd $VPN_PASSWORD *" >> /etc/ppp/chap-secrets echo "ms-dns 8.8.8.8" >> /etc/ppp/pptpd-options echo "ms-dns 8.8.4.4" >> /etc/ppp/pptpd-options service pptpd restart echo "net.ipv4.ip_forward = 1" >> /etc/sysctl.conf sysctl -p iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE && iptables-save