pptpVPN - TuPengXiong/TuPengXiong.github.io GitHub Wiki
#!/bin/bash
#
# Author: yeho <lj2007331 AT gmail.com>
# Blog: https://blog.linuxeye.com
#
# Installs a PPTP VPN-only system for CentOS
# Check if user is root
[ $(id -u) != "0" ] && { echo -e "\033[31mError: You must be root to run this script\033[0m"; exit 1; }
export PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
clear
printf "
#######################################################################
# LNMP/LAMP/LANMP for CentOS/RadHat 5+ Debian 6+ and Ubuntu 12+ #
# Installs a PPTP VPN-only system for CentOS #
# For more information please visit https://blog.linuxeye.com/31.html #
#######################################################################
"
[ ! -e '/usr/bin/curl' ] && yum -y install curl
VPN_IP=`curl ipv4.icanhazip.com`
VPN_USER="linuxeye"
VPN_PASS="linuxeye"
VPN_LOCAL="172.16.0.226"
VPN_REMOTE="192.168.100.151-200"
while :; do echo
read -p "Please input username: " VPN_USER
[ -n "$VPN_USER" ] && break
done
while :; do echo
read -p "Please input password: " VPN_PASS
[ -n "$VPN_PASS" ] && break
done
clear
if [ -f /etc/redhat-release -a -n "`grep ' 7\.' /etc/redhat-release`" ];then
#CentOS_REL=7
if [ ! -e /etc/yum.repos.d/epel.repo ];then
cat > /etc/yum.repos.d/epel.repo << EOF
[epel]
name=Extra Packages for Enterprise Linux 7 - \$basearch
#baseurl=http://download.fedoraproject.org/pub/epel/7/\$basearch
mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-7&arch=\$basearch
failovermethod=priority
enabled=1
gpgcheck=0
EOF
fi
for Package in wget make openssl gcc-c++ ppp pptpd iptables iptables-services
do
yum -y install $Package
done
echo 'net.ipv4.ip_forward = 1' >> /etc/sysctl.conf
elif [ -f /etc/redhat-release -a -n "`grep ' 6\.' /etc/redhat-release`" ];then
#CentOS_REL=6
for Package in wget make openssl gcc-c++ iptables ppp
do
yum -y install $Package
done
sed -i '[email protected]_forward.*@net.ipv4.ip_forward = 1@g' /etc/sysctl.conf
rpm -Uvh http://poptop.sourceforge.net/yum/stable/rhel6/pptp-release-current.noarch.rpm
yum -y install pptpd
else
echo -e "\033[31mDoes not support this OS, Please contact the author! \033[0m"
exit 1
fi
echo "1" > /proc/sys/net/ipv4/ip_forward
sysctl -p /etc/sysctl.conf
[ -z "`grep '^localip' /etc/pptpd.conf`" ] && echo "localip $VPN_LOCAL" >> /etc/pptpd.conf # Local IP address of your VPN server
[ -z "`grep '^remoteip' /etc/pptpd.conf`" ] && echo "remoteip $VPN_REMOTE" >> /etc/pptpd.conf # Scope for your home network
[ -z "`grep '^stimeout' /etc/pptpd.conf`" ] && echo "stimeout 172800" >> /etc/pptpd.conf
if [ -z "`grep '^ms-dns' /etc/ppp/options.pptpd`" ];then
cat >> /etc/ppp/options.pptpd << EOF
ms-dns 172.16.0.1 # inter DNS Primary
ms-dns 223.5.5.5 # Aliyun DNS Primary
ms-dns 114.114.114.114 # 114 DNS Primary
ms-dns 8.8.8.8 # Google DNS Primary
ms-dns 209.244.0.3 # Level3 Primary
ms-dns 208.67.222.222 # OpenDNS Primary
EOF
fi
echo "$VPN_USER pptpd $VPN_PASS *" >> /etc/ppp/chap-secrets
ETH=`route | grep default | awk '{print $NF}'`
[ -z "`grep '1723 -j ACCEPT' /etc/sysconfig/iptables`" ] && iptables -I INPUT 4 -p tcp -m state --state NEW -m tcp --dport 1723 -j ACCEPT
[ -z "`grep 'gre -j ACCEPT' /etc/sysconfig/iptables`" ] && iptables -I INPUT 5 -p gre -j ACCEPT
iptables -t nat -A POSTROUTING -o $ETH -j MASQUERADE
iptables -I FORWARD -p tcp --syn -i ppp+ -j TCPMSS --set-mss 1356
service iptables save
sed -i 's@^-A INPUT -j REJECT --reject-with icmp-host-prohibited@#-A INPUT -j REJECT --reject-with icmp-host-prohibited@' /etc/sysconfig/iptables
sed -i 's@^-A FORWARD -j REJECT --reject-with icmp-host-prohibited@#-A FORWARD -j REJECT --reject-with icmp-host-prohibited@' /etc/sysconfig/iptables
service iptables restart
chkconfig iptables on
service pptpd restart
chkconfig pptpd on
clear
echo -e "You can now connect to your VPN via your external IP \033[32m${VPN_IP}\033[0m"
echo -e "Username: \033[32m${VPN_USER}\033[0m"
echo -e "Password: \033[32m${VPN_PASS}\033[0m"
来源
152 rpm -q ppp
153 yum install -y perl ppp
154 rpm -Uvh http://poptop.sourceforge.net/yum/stable/rhel6/pptp-release-current.noarch.rpm
155 yum install pptpd
156 cd /etc/ppp/
157 ll
158 cat pap-secrets
159 cat chap-secrets
160 cp /etc/ppp/options.pptpd /etc/ppp/options.pptpd.bak
161 ls
162 ll
163 ls
164 cd options
165 cat options
166 cp /etc/ppp/options.pptpd /etc/ppp/options.pptpd.bak
167 ssh [email protected]
168 rpm -q ppp
169 rpm -Uvh http://poptop.sourceforge.net/yum/stable/rhel6/pptp-release-current.noarch.rpm
170 yum install pptpd
171 ls
172 pwd
173 scp -r [email protected]:/etc/ppp/ ./
174 ll
175 cd ppp/
176 mv -f * ../
177 ll
178 cd ../
179 ll
180 rm -rf ppp/
181 ls
182 cd ../
183 ll
184 scp [email protected]:/etc/pptpd.conf ./
185 ll
186 cat pptpd.conf
187 service pptpd start
服务器 vpn server nat
iptables -t nat -A POSTROUTING -o eth0 -s 172.16.100.0/24 -j MASQUERADE
本地网络vpn client
route -p add 172.16.100.0 mask 255.255.255.0 172.16.0.226