Skip to content

Instantly share code, notes, and snippets.

@likai24
Last active October 11, 2016 03:46
Show Gist options
  • Save likai24/9ca95dffb62d4cff320f9c724a1b8b4f to your computer and use it in GitHub Desktop.
Save likai24/9ca95dffb62d4cff320f9c724a1b8b4f to your computer and use it in GitHub Desktop.
#!/bin/bash
# For detail introduction, please see http://www.jamescoyle.net/how-to/963-set-up-linux-pptp-client-from-the-terminal
# exit when error occur
set -o errexit
set -o nounset
# Bash will remember & return the highest exitcode in a chain of pipes.
# This way you can catch the error in case mysqldump fails in `mysqldump |gzip`
set -o pipefail
domain='yourdomain.com'
pptpuser='username'
password='password'
host='yourdomain.com'
# Install pptpd
sudo apt-get install pptp-linux -y
# Set up password and user name in chap-secret
echo -e "
#[USER] [SERVER] [SECRET] [IP]
${pptpuser} PPTP ${password} *
" | sudo tee --append /etc/ppp/chap-secrets > /dev/null
# Set up route, use netstat -rn to check
echo -e "
#!/bin/bash
# all traffic goes to ppp0
route add -net 0.0.0.0/32 dev ppp0
" | sudo tee --append /etc/ppp/ip-up.d/${domain}-traffic > /dev/null
chmod +x /etc/ppp/ip-up.d/${domain}-traffic
# Set up PPTP configuration
echo -e "
pty \"pptp ${host} --nolaunchpppd\"
name ${pptpuser}
remotename PPTP
require-mppe-128
file /etc/ppp/options.pptp
ipparam ${domain}
" | sudo tee --append /etc/ppp/peers/${domain} > /dev/null
# Step 6. Configure firewall
iptables -A INPUT -i pptp -j ACCEPT
iptables -A OUTPUT -j ACCEPT
iptables-save
# start client
sudo pon ${domain}
# or use sudo crontab -e to edit, root is required: * * * * * su -c "home/user/scripts/vpn_check.sh"
su -c "echo \"* * * * * root bash $(pwd)/vpn_check.sh\" > /etc/cron.d/vpn_check"
####vpn_check####
## see https://gist.github.com/likai24/508da69413ecc7200929d5fa6fdad901
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment