Skip to content

Instantly share code, notes, and snippets.

@beherca
Last active September 6, 2019 09:42
Show Gist options
  • Save beherca/3f5885f2fef8a6c6db92 to your computer and use it in GitHub Desktop.
Save beherca/3f5885f2fef8a6c6db92 to your computer and use it in GitHub Desktop.
Install PPTP Client on Ubuntu
#!/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
echo -n "Domain: "
read domain
echo -n "PPTP User: " # use -n to prompt inline label
read pptpuser
echo -n "Password: "
read password
echo -n "Host IP or Domain: "
read host
# 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}
# check ifconfig to see ppp0 interface
#poff ${domain}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment