“ubuntu教程”linux && ubuntu 一键安装pptp vpn

来源: 电脑维修教程 阅读:     发表时间:

http://siliotto.blog.51cto.com/8887165/1623735 一,centos 6.x #!/bin/bash -x # # drewsymo/vpn # # installs a pptp vpn-only system for centos # # @package vpn 2.0 # @since vpn 1.0 # @author drew morr

http://siliotto.blog.51cto.com/8887165/1623735

一,centos 6.x

#!/bin/bash -x

#

# drewsymo/vpn

#

# installs a pptp vpn-only system for centos

#

# @package vpn 2.0

# @since vpn 1.0

# @author drew morris

#

(

vpn_ip=`curl ipv4.icanhazip.com>/dev/null 2>&1`

vpn_user="username"

vpn_pass="userpasswd"

vpn_local="192.168.8.1"

vpn_remote="192.168.8.151-200"

yum -y groupinstall "development tools"

rpm -uvh http://poptop.sourceforge.net/yum/stable/rhel6/pptp-release-current.noarch.rpm

yum -y install policycoreutils policycoreutils

yum -y install ppp pptpd

yum -y update

mknod /dev/ppp c 108 0

echo "mknod /dev/ppp c 108 0" >> /etc/rc.local

echo "1" > /proc/sys/net/ipv4/ip_forward

sed -i 's/net.ipv4.ip_forward = 0/net.ipv4.ip_forward = 1/g' /etc/sysctl.conf

sysctl -p /etc/sysctl.conf

echo "localip $vpn_local" >> /etc/pptpd.conf # local ip address of your vpn server

echo "remoteip $vpn_remote" >> /etc/pptpd.conf # scope for your home network

echo "ms-dns 8.8.8.8" >> /etc/ppp/options.pptpd # google dns primary

echo "ms-dns 209.244.0.3" >> /etc/ppp/options.pptpd # level3 primary

echo "ms-dns 208.67.222.222" >> /etc/ppp/options.pptpd # opendns primary

echo "$vpn_user pptpd $vpn_pass *" >> /etc/ppp/chap-secrets

service iptables start

echo "iptables -t nat -a postrouting -o eth0 -j masquerade" >> /etc/rc.local

iptables -t nat -a postrouting -o eth0 -j masquerade

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

service iptables restart

service pptpd restart

chkconfig pptpd on

echo -e 'e[37;44m'"033[1m installation log: /var/log/vpn-installer.log 033[0m"

echo -e 'e[37;44m'"033[1m you can now connect to your vpn via your external ip ($vpn_ip)033[0m"

echo -e 'e[37;44m'"033[1m username: $vpn_user033[0m"

echo -e 'e[37;44m'"033[1m password: $vpn_pass033[0m"

) 2>&1 | tee /var/log/vpn-installer.log

备注,转发法则,若是你的服务器是云主机,

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}'`

这个取值并非你的外网ip,请直接填写便可。like this

iptables -t nat -a postrouting -s 192.168.8.0/24 -j snat --to-source 23.91.98.xx

二,ubuntu 12.xx

#!/bin/bash

path=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin

export path

clear

cur_dir=$(pwd)

if [ $(id -u) != "0" ]; then

printf "error: you must be root to run this script!"

exit 1

fi

echo "#############################################################"

echo "# pptp vpn auto install"

echo "# env: debian/ubuntu"

echo "# created by zombie on 2015.03.23"

echo "# version: 1.0"

echo "#############################################################"

echo ""

apt-get -y update

apt-get -y install pptpd

cat >>/etc/pptpd.conf<

localip 10.10.10.1

remoteip 10.10.10.2-254

eof

cp /etc/ppp/pptpd-options /etc/ppp/pptpd-options.old

cat >/etc/ppp/pptpd-options<

name pptpd

refuse-pap

refuse-chap

refuse-mschap

require-mschap-v2

require-mppe-128

ms-dns 8.8.8.8

ms-dns 8.8.4.4

ms-dns 209.244.0.3

ms-dns 208.67.222.222

proxyarp

debug

dump

lock

nobsdcomp

novj

novjccomp

logfile /var/log/pptpd.log

eof

cat >>/etc/ppp/chap-secrets<

user * pwd *

eof

sed -i 's/#net.ipv4.ip_forward=1/net.ipv4.ip_forward=1/g' /etc/sysctl.conf

sysctl -p

iptables-save > /etc/iptables.down.rules

iptables -a input -p tcp --dport 22 -j accept

iptables -a output -p tcp --dport 22 -j accept

iptables -a input -p tcp --dport 1723 -j accept

iptables -a output -p tcp --dport 1723 -j accept

iptables -t nat -a postrouting -s 10.0.0.0/8 -j masquerade

iptables -t nat -a postrouting -s 10.0.0.0/8 -j snat --to-source `ifconfig | grep 'inet addr:'| grep -v '127.0.0.1' | cut -d: -f2 | awk 'nr==1 { print $1}'`

#iptables -i forward -p tcp --syn -i ppp+ -j tcpmss --set-mss 1356

iptables -a forward -s 10.0.0.0/8 -p tcp -m tcp --tcp-flags fin,syn,rst,ack syn -j tcpmss --set-mss 1356

iptables-save > /etc/iptables.up.rules

cat >>/etc/ppp/pptpd-options<

pre-up iptables-restore < /etc/iptables.up.rules

post-down iptables-restore < /etc/iptables.down.rules

eof

/etc/init.d/pptpd restart

备注,若是呈现619等报错,解除防火墙法则已开启响应端口的环境下,请查看/etc/ppp/pptpd-options

将 pre-up,post-down,开首字样的段落注释失落便可。

以上是:解决“ubuntu教程”linux && ubuntu 一键安装pptp vpn问题的详细资料教程